The shortest problem

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 346    Accepted Submission(s): 167

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<=104 ) , t(0<=t<=105) 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
 
Source
 
解题:由于能被11整除的数的特点是奇数位与偶数位的和的绝对值可以被11整除,所以,搞一下就可以了
 
 #include <bits/stdc++.h>
using namespace std;
int cur = ,n,m,d[];
int solve(int x) {
int a[] = {};
cur = ;
while(x) {
a[cur^] += x%;
x /= ;
cur ^= ;
}
if(cur&) swap(d[],d[]);
d[] += a[];
d[] += a[];
return d[] + d[];
}
int main() {
int cs = ;
while(scanf("%d%d",&n,&m),(~n) && (~m)) {
d[] = d[] = ;
for(int i = ; i <= m; ++i) n = solve(n);
printf("Case #%d: %s\n",cs++,abs(d[]-d[])%?"No":"Yes");
}
return ;
}

最新文章

  1. Python for Infomatics 第13章 网页服务一(译)
  2. jq 页面延时刷新
  3. Windows Azure 入门系列课程Windows Azure 入门系列课程
  4. ABP入门系列(5)——创建应用服务
  5. swift(一)
  6. [luogu 1880]石子合并
  7. MySQL 高可用MHA安装部署以及故障转移详细资料汇总 转
  8. JSON解析例子
  9. STMP发送邮件被当垃圾邮件处理的解决方法
  10. 动手实现Expression翻译器1
  11. ubuntu14.04下安装有道词典
  12. MarkDown---超强文本编辑器
  13. 解决IIS配置问题
  14. 校验台湾身份证号码的js脚本
  15. windows mysql绿色版配置
  16. PL2303 Windows8.1驱动
  17. log4net记录系统错误日志到文本文件用法详解(最新)
  18. RHEL7 -- systemd
  19. 字符串hash的学习部分 可以算是模板?
  20. 加快npm包安装的方法

热门文章

  1. eclipse 去掉Eclipse打开后定期弹出Usage Data Upload对话框
  2. Strtus配置Tomcat出现问题
  3. CF909B Segments
  4. Python模块路径查找
  5. 60款开源云应用【Part 3】(60 Open Source Apps You Can Use in the Cloud)
  6. Spring+MyBatis双数据库配置
  7. Share Your Knowledge and Experiences
  8. 【UML】UML世界的构成
  9. Cocos2d-x学习资源集锦+有奖抽楼活动
  10. spring Batch实现数据库大数据量读写