LabmemNo_012LzTopic @ 2024-02-24 11:35:39
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int a[10]={0}, ans, u = 0;
char s[14];
scanf("%s", s);//输入ISBN号码
for (int i = 0; i < 13; i++)
{
ans = s[i] - 48;
if (ans >= 0 && ans <= 9)a[u++] = ans;
//判断是否为字符‘1’到‘9’,是就计入数组a中
}
u = 1;
ans = 0;
for (int i = 0; i < 9; i++)//计算识别码
{
ans += (a[i] * u++);
}
ans = ans % 11;
if (a[9] == ans)printf("Right");//输出
else
{
printf("%d-%d%d%d-%d%d%d%d%d-%d",
a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], ans);
}
return 0;
}
by zjjc1104111 @ 2024-02-24 11:51:01
X$。
by LabmemNo_012LzTopic @ 2024-02-24 12:37:26
@zjjc1104111 感谢大佬!!1
by LabmemNo_012LzTopic @ 2024-02-24 13:40:39
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int a[10]={0}, ans, u = 0;
char s[15];
scanf("%s", s);//输入ISBN号码
for (int i = 0; i < 13; i++)
{
ans = s[i] - 48;
if (i < 12)
{
if (ans >= 0 && ans <= 9)a[u++] = ans;
}
else
{//判断最后的识别码是否输入2个字符
if (s[14] == '\0')a[u] = ans * 10 + (s[i + 1] - 48);
else a[u] = ans;
}
}
u = 1;
ans = 0;
for (int i = 0; i < 9; i++)
{
ans += (a[i] * u++);
}
ans = ans % 11;
if (a[9] == ans)printf("Right");
else
{
printf("%d-%d%d%d-%d%d%d%d%d-%d",
a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], ans);
}
return 0;
}
@zjjc1104111
by LabmemNo_012LzTopic @ 2024-02-24 13:41:35
@zjjc1104111 我这样改过后还是有问题
by yun123123 @ 2024-02-24 15:37:12
题目的意思是你最后算出的识别码可能会是10,你要把它换成X,不是给出的序列码中的识别码会有10
by zjjc1104111 @ 2024-02-25 20:07:45
@LabmemNo_012LzTopic 输出也要改成10
by zjjc1104111 @ 2024-02-25 20:08:12
该成x