题解 | #[NOIP2008]ISBN号码#
[NOIP2008]ISBN号码
http://www.nowcoder.com/practice/95712f695f27434b9703394c98b78ee5
大家凑合看看吧
#include <stdio.h>
char sum(int word,int pub,int num);
int main()
{
int word,pub,num;
char code;
scanf("%d-%d-%d-%c",&word,&pub,&num,&code);
if(sum(word,pub,num)==code)
printf("Right");
else
printf("%d-%d-%d-%c",word,pub,num,sum(word,pub,num));
return 0;
}
char sum(int word,int pub,int num)
{
int result= (word+pub/100*2+pub/10%10*3+pub%10*4+num/10000*5+
num/1000%10*6+num/100%10*7+num/10%10*8+num%10*9)%11;
if(result>=0&&result<=9)
return result+'0';
else
return 'X';
}