本文共 2915 字,大约阅读时间需要 9 分钟。
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 5830 | Accepted: 3019 |
Description
id number : 1 3 9 0 2 7 2factors : 9 7 3 9 7 3 9products : 9 21 27 0 14 21 18Here the checksum is 9+21+27+0+14+21+18 = 110. The last digit is zero, so the id is valid. Sometimes students have very bad handwriting and the teaching assistents have a hard time identifying the id’s. You're asked to help in special cases, where exactly one digit is unreadable. In that case, the missing digit can be computed (there's always exactly one correct digit, thanks to 9, 3 and 7 being relatively prime to 10). Note that the students always begin concentrated and thus the first digit will always be readable (and not zero).
Input
Output
Sample Input
413?02723?5678345?78314?592
Sample Output
Scenario #1:1390272Scenario #2:335678Scenario #3:345778Scenario #4:3146592
Hint
Source
#include#include #include char num[10];int mul[3] = {9, 3, 7};int main(void){ int ii, casenum; int sum, pos, need; int len, value; int i, j; scanf("%d", &casenum); for (ii = 1; ii <= casenum; ii++){ scanf("%s", num); len = strlen(num); sum = 0; for (i = len - 1, j = 0; i >= 0; i --, j++){ if (num[i] != '?'){ sum += mul[j % 3] * (num[i] - '0'); } else{ pos = i; need = mul[j % 3]; } } for (value = 0, i = 0; i <= 9; i++){ if ((i * need + sum) % 10 == 0){ value = i; break; } } num[pos] = value + '0'; printf("Scenario #%d:\n%s\n\n", ii, num); } return 0;}
转载地址:http://pooji.baihongyu.com/