You can say 11
Time Limite: 1 second
Introduction to the problem
Your job is, given a positive number N, determine if it is a multiple of eleven.
Description of the input
The 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 output
The output of the program shall indicate, for each input number, if it is a multiple of eleven or not.
Sample input:
112233
30800
2937
323455693
5038297
112234
0
Sample output
112233 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.
能被11整除的数。奇数位数的和与偶数位数的和的差能被11整除。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
#define maxn 1005
#define inf 0x7ffffff
pair <int ,int > p;
char arr[maxn];
int n;
//int cmpD(Node a,Node b){
// return a.h > b.h;
//}
//int cmpI(Node a,Node b){
// return a.h < b.h;
//}
int main()
{
while(gets(arr)){
if(strcmp(arr,"0") == 0){
break;
}
int len = strlen(arr);
int odd = 0;
int even = 0;
for(int i = 0; i < len;i += 2){
odd += arr[i] - '0';
}
for(int i = 1; i < len; i += 2){
even += arr[i] - '0';
}
if((odd - even) % 11 == 0){
printf("%s is a multiple of 11.\n",arr);
}else{
printf("%s is not a multiple of 11.\n",arr);
}
}
return 0;
}