HDU 5373_The shortest problem
2015-08-13 11:04
351 查看
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1009 Accepted Submission(s): 507
Problem Description
In this problem, we should solve an interesting game. At first, we have an integer n, then we begin to make some funny change. We sum up every digit of the n, then insert it to the tail of the number n, then let the new number be the interesting number n. repeat
it for t times. When n=123 and t=3 then we can get 123->1236->123612->12361215.
Input
Multiple input.
We have two integer n (0<=n<=$10^4$ ) , t(0<=t<=$10^5$) in each row.
When n==-1 and t==-1 mean the end of input.
Output
For each input , if the final number are divisible by 11, output “Yes”, else output ”No”. without quote.
Sample Input
35 2
35 1
-1 -1
Sample Output
Case #1: Yes
Case #2: No
这道题的意思是不断地往后面加上之前数字的总和,然后判断这个数是否能被11整除
所以只要判断最后形成的那个数的奇数位和偶数位差的绝对值能否被11整除即可
事实上,一开始算好输入数字的和,然后再不断地加上那个和的每个位数上面的和即可,顺便算好奇数位和偶数位的和,最后就可以求出奇数位和偶数位的差的绝对值能否被11整除了。
Total Submission(s): 1009 Accepted Submission(s): 507
Problem Description
In this problem, we should solve an interesting game. At first, we have an integer n, then we begin to make some funny change. We sum up every digit of the n, then insert it to the tail of the number n, then let the new number be the interesting number n. repeat
it for t times. When n=123 and t=3 then we can get 123->1236->123612->12361215.
Input
Multiple input.
We have two integer n (0<=n<=$10^4$ ) , t(0<=t<=$10^5$) in each row.
When n==-1 and t==-1 mean the end of input.
Output
For each input , if the final number are divisible by 11, output “Yes”, else output ”No”. without quote.
Sample Input
35 2
35 1
-1 -1
Sample Output
Case #1: Yes
Case #2: No
这道题的意思是不断地往后面加上之前数字的总和,然后判断这个数是否能被11整除
所以只要判断最后形成的那个数的奇数位和偶数位差的绝对值能否被11整除即可
事实上,一开始算好输入数字的和,然后再不断地加上那个和的每个位数上面的和即可,顺便算好奇数位和偶数位的和,最后就可以求出奇数位和偶数位的差的绝对值能否被11整除了。
#include<iostream> #include<string.h> #include<stdio.h> #include<math.h> using namespace std; int n,t; int sum; int num; int even,odd; int judge(int a) { int kk=a; int k=0; while(kk) { k++; kk/=10; } num+=k; kk=a; for(int i=num;i>num-k;i--) { if(i%2==0) even+=kk%10; else odd+=kk%10; kk/=10; } return even+odd; } int main() { int cas=0; while(scanf("%d %d",&n,&t)!=EOF && n!=-1 && t!=-1) { cas++; num=0; sum=0; odd=0; even=0; sum+=judge(n); for(int i=0;i<t;i++) sum=judge(sum); printf("Case #%d: ",cas); if(abs(odd-even)%11==0) printf("Yes\n"); else printf("No\n"); } return 0; }
相关文章推荐
- HDU 1568
- HDU1290
- HDU1568(Fobonacci公式)
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)
- HDU 1405
- HDU 1297
- hdu 1205
- hdu 2087
- hdu 1016
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- HDU 1000
- HDU 1001
- HDU 1622 Trees On The Level
- HDU 1063 Exponentiation
- Hdu5033
- HDU 1166 敌兵布阵
- HDU Rightmost Digit
- hdu 1002
- 贪心 hdu 1003
- hdu 1004