UVA Solution 333 - Recognizing Good ISBNs - Solution in C, C++ | Volume 3
UVA Online Judge Solution 333 - Recognizing Good ISBNs| Volume 3
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=269
Problem Name: 333 - Recognizing Good ISBNs
Problem Number : UVA - 333 - Recognizing Good ISBNs
Online Judge : UVA Online Judge Solution
Volume: 3
Solution Language : C, C plus plus
UVA Solution 333 - Recognizing Good ISBNs Code in C, CPP:
#include <stdio.h> int main() { char s[105]; while(gets(s)) { char *p = s; int d = 0, flag = 0, i, j, sum = 0, ten; while(*p == ' ') p++; for(i = 0; p[i]; i++) { if(p[i] >= '0' && p[i] <= '9') { d++; if(d <= 9) sum += (11-d)*(p[i]-'0'); else ten = p[i]-'0'; } else if(p[i] != ' ' && p[i] != '-') { if(d == 9 && p[i] == 'X') { d++; ten = 10; continue; } flag = 1; } } i--; while(i >= 0 && p[i] == ' ') p[i] = '\0', i--; printf("%s is ", p); sum += ten; if(d != 10 || flag || sum%11) { puts("incorrect."); continue; } else puts("correct."); } return 0; }
No comments:
Post a Comment