NYOJ103A+B Problem II
来源:互联网 发布:国外数据新闻案例分析 编辑:程序博客网 时间:2024/06/13 16:25
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=103
纯模拟,没啥好说的 - -
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;char s[1010];char s1[1005];int s2[1005];int len_s;int len_s1;void Reverse(char s[],int len){ for(int i = 0,j = len - 1;i < j && i < len / 2;++i,--j) { char t = s[i]; s[i] = s[j]; s[j] = t; }}int main(){ int cnt = 1; int _; scanf("%d",&_); while(_--) { memset(s2,0,sizeof(s2)); scanf("%s%s",s,s1); len_s = strlen(s); len_s1 = strlen(s1); printf("Case %d:\n",cnt++); printf("%s + %s = ",s,s1); Reverse(s,len_s); Reverse(s1,len_s1); //printf("%s %s\n",s,s1); int c = 0; int i; for(i = 0;i < min(len_s,len_s1);++i) { s2[i] = (s[i] - '0' + s1[i] - '0' + c) % 10; //printf("%d %d %d %d\n",s[i] - '0',s1[i] - '0',s2[i],s[i] - '0' + s1[i] - '0' + c); c = (s[i] - '0'+ s1[i] - '0' + c) / 10; } while(i < len_s) { s2[i] = (s[i] - '0' + c) % 10; c = (s[i] - '0' + c) / 10; i++; } while(i < len_s1) { s2[i] = (s1[i] - '0' + c) % 10; c = (s1[i] - '0' + c) / 10; i++; } while(c) { s2[i++] = c % 10; c /= 10; } for(int j = i - 1;j >= 0;--j) printf("%d",s2[j]); printf("\n"); } return 0;}
0 0
- nyoj103A+B Problem II
- NYOJ103A+B Problem II
- hdu1002A + B Problem II
- A + B Problem II
- A + B Problem II
- A + B problem II
- A + B Problem II
- hdu1002A + B Problem II
- A + B Problem II
- A + B Problem II
- A + B Problem II
- A + B Problem II
- A + B Problem II
- A + B Problem II
- A + B Problem II
- A+B Problem II
- A+B problem II
- HDU_1002A + B Problem II
- JFrame(框架)中添加和设置JPanel(面板
- 2011.6-2012
- 数据类型转换
- 初识A*算法
- PHP:echo中逗号与点号的区别
- NYOJ103A+B Problem II
- 正则表达式及常用类
- DB2数据库切换为oracle数据库经验教训总结
- linux文件权限
- postInvalidate和invalidate的区别
- RGB像素明度计算公式
- 集合_1
- 我的Android网络框架之旅(四)
- 集合_2