标签:
简单模拟题,可以利用一下能被11整除的数的特点:奇数位的数字和与偶数位的数字和之差能被11整除。
1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cstdio> 5 using namespace std; 6 7 const int N = 1000000; 8 int s[N]; 9 int mid[N]; 10 11 int main () 12 { 13 int n, t, _case = 0; 14 while ( scanf("%d%d", &n, &t) != EOF ) 15 { 16 if ( n == -1 && t == -1 ) break; 17 int sum = 0, p = 0, cnt = 0; 18 while ( n ) 19 { 20 sum += n % 10; 21 mid[p++] = n % 10; 22 n /= 10; 23 } 24 for ( int i = p - 1; i >= 0; i-- ) 25 { 26 s[cnt++] = mid[i]; 27 } 28 while ( t-- ) 29 { 30 int tmp = sum; 31 p = 0; 32 while ( tmp ) 33 { 34 sum += tmp % 10; 35 mid[p++] = tmp % 10; 36 tmp /= 10; 37 } 38 for ( int i = p - 1; i >= 0; i-- ) 39 { 40 s[cnt++] = mid[i]; 41 } 42 } 43 int ssum = 0; 44 for ( int i = 0; i < cnt; i++ ) 45 { 46 if ( i & 1 ) ssum += s[i]; 47 else ssum -= s[i]; 48 } 49 _case++; 50 if ( ssum % 11 == 0 ) 51 { 52 printf("Case #%d: Yes\n", _case); 53 } 54 else 55 { 56 printf("Case #%d: No\n", _case); 57 } 58 } 59 return 0; 60 }
标签:
原文地址:http://www.cnblogs.com/huoxiayu/p/4722165.html