UVa - 10929 - You can say 11

上题目

Problem C - 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.

 

  题意很简单,就是给你一个最多1000位的整数,问你这个数能否被11整除。这里之处使用大数模运算就可以了,具体操作看代码。

上代码

 1 #include <stdio.h>
 2 #include <string.h>
 3 #define max(x,y) (x > y ?  x : y)
 4 #define MAX (1000+10)
 5 using namespace std;
 6 
 7 char num[MAX];
 8 
 9 int main()
10 {
11     int len,i;
12     long long ans;
13     //freopen("data.txt","r",stdin);
14     while(scanf("%s",num),strcmp(num,"0"))
15     {
16         len=strlen(num);
17         ans=0;
18         for(i=0;i<len;i++)
19             ans=(ans*10+(num[i]-'0'))%11;
20         if(!ans) printf("%s is a multiple of 11.\n",num);
21         else printf("%s is not a multiple of 11.\n",num);
22     }
23     return 0;
24 }
10929

 

 

posted @ 2013-08-08 22:49  海拉鲁的林克  阅读(300)  评论(0编辑  收藏  举报