洛谷P1055


用C语言实现 注意一下当给出验证值为X 时的情况


#include



int main ()
{
char ch[20];

int i, sum = 0;
int n = 0;
int m;
/*FILE *fp;
fp = fopen("111.txt", "r");
fgets(ch, 14, fp);*/
gets(ch);

for (i = 0; i < 12; i++)
{
if (ch[i] == '\0')
break;
else if (ch[i] == '-')
continue;
else
{
n++;
m = ch[i] - 48;
sum = m * n + sum;
}
}
sum = sum % 11;

if (sum == 10 && ch[12] == 'X')
printf("Right");
else if (sum == ch[12] - 48)
printf("Right");
else
{
if (sum == 10)
ch[12] = sum + 78;
else
ch[12] = sum + 48;
for (i = 0; i < 13; i++)

printf("%c", ch[i]);
}

return 0; 

你可能感兴趣的:(洛谷小测)