UVa 10929 You can say 11 (数论)2014-07-12 synapse7 10929 - You can say 11Time limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1870
Introduction to the problemYour job is, given a positive number N, determine if it is a multiple of eleven.
Description of the inputThe input is a file such that each line contains a positive number. A line containing the number 0 is the end of the input. The given numbers can contain up to 1000 digits.
Description of the outputThe output of the program shall indicate, for each input number, if it is a multiple of eleven or not.
Sample input:11223330800293732345569350382971122340
Sample output112233 is a multiple of 11.30800 is a multiple of 11.2937 is a multiple of 11.323455693 is a multiple of 11.5038297 is a multiple of 11.112234 is not a multiple of 11.方法1:直接从个位数开始mod 11计算。
/*0.026s*/#include<cstdio>#include<cstring>char s[1005];int main(void){int remainder;while (gets(s), strcmp(s, "0")){remainder = 0;for (int i = 0; s[i]; i++)remainder = (remainder * 10 + (s[i] & 15)) % 11;if (remainder) printf("%s is not a multiple of 11.
", s);else printf("%s is a multiple of 11.
", s);}return 0;}