UVa 10929 You can say 11
解題策略
數學常識老梗題,快速判斷11的倍數,把奇數位和偶數位相減,結果必為11的倍數。注意
請通過這個心機測資 00011
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* UVa 10929 You can say 11 (AC) | |
* Author: chchwy | |
* Last Modified: 2010.01.30 | |
*/ | |
#include<iostream> | |
using namespace std; | |
int main() | |
{ | |
string num; | |
while ( getline(cin, num) ) | |
{ | |
if (num[0] == '0' && num.length() == 1 ) break; | |
int sum = 0; | |
for (int i = 0; i < num.length(); i += 2) | |
sum += (num[i] - '0'); | |
for (int i = 1; i < num.length(); i += 2) | |
sum -= (num[i] - '0'); | |
if (sum % 11 == 0) | |
cout << num << " is a multiple of 11.\n"; | |
else | |
cout << num << " is not a multiple of 11.\n"; | |
} | |
} |
留言
張貼留言