題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=21&page=show_problem&problem=1870
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| #include <iostream> #include <cmath>
using namespace std;
int main(){ string str;
while(cin >> str){ if(str == "0") break; int odd = 0, even = 0; for(int i=0; i<str.size(); ++i){ if(i%2 == 1) odd += str[i]-48; else even += str[i]-48; } int diff = abs(odd - even); if(diff % 11 == 0) cout << str << " is a multiple of 11.\n"; else cout << str << " is not a multiple of 11.\n"; } return 0; }
|