HDU2096
来源:互联网 发布:中国 期刊 数据库 编辑:程序博客网 时间:2024/06/05 03:57
小明A+B
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 31695 Accepted Submission(s): 15111
Problem Description
小明今年3岁了, 现在他已经能够认识100以内的非负整数, 并且能够进行100以内的非负整数的加法计算.
对于大于等于100的整数, 小明仅保留该数的最后两位进行计算, 如果计算结果大于等于100, 那么小明也仅保留计算结果的最后两位.
例如, 对于小明来说:
1) 1234和34是相等的
2) 35+80=15
给定非负整数A和B, 你的任务是代表小明计算出A+B的值.
Input
输入数据的第一行为一个正整数T, 表示测试数据的组数. 然后是T组测试数据. 每组测试数据包含两个非负整数A和B(A和B均在int型可表示的范围内).
Output
对于每组测试数据, 输出小明A+B的结果.
Sample Input
2
35 80
15 1152
Sample Output
15
67
坑点在int+int会超出int范围
这题是用字符串做的写得太麻烦了
用其实int64相加模一下就完了
就当练习写字符串了
#include "iostream"#include "cstdio"#include "cstring"using namespace std;int main(){ int count; while(scanf("%d",&count)!=EOF) { for(int i=1;i<=count;i++) { string a,b; cin>>a>>b; long lena,lenb; lena=a.length(); lenb=b.length(); long numa,numb; if(lena==1&&lenb==1) { numa=a[lena-1]-'0'; numb=b[lenb-1]-'0'; if((numa+numb)>=100) { cout<<numa+numb-100<<endl; } else cout<<numa+numb<<endl; continue; } if(lenb>1&&lena==1) { numa=a[lena-1]-'0'; numb=b[lenb-1]-'0'+10*(b[lenb-2]-'0'); if((numa+numb)>=100) { cout<<numa+numb-100<<endl; } else cout<<numa+numb<<endl; continue; } if(lena>1&&lenb==1) { numa=a[lena-1]-'0'+10*(a[lena-2]-'0'); numb=b[lenb-1]-'0'; if((numa+numb)>=100) { cout<<numa+numb-100<<endl; } else cout<<numa+numb<<endl; continue; } if(lena>1&&lenb>1) { numa=a[lena-1]-'0'+10*(a[lena-2]-'0'); numb=b[lenb-1]-'0'+10*(b[lenb-2]-'0'); if((numa+numb)>=100) { cout<<numa+numb-100<<endl; } else cout<<numa+numb<<endl; continue; } } }}
0 0
- HDU2096
- HDU2096
- hdu2096 Collecting Bugs
- hdu2096 小明A+B
- hdu2096 小明A+B
- hdu2096小明A+B
- hdu2096小明A+B
- hdu2096 小明A+B
- HDU2096 小明A+B
- Hdu2096 小明A+B
- HDU2096小明A+B
- HDU2096 小明A+B【水题】
- HDU2096——小明A+B
- hdu2096 小明A+B(C语言)
- hdu2096 小明A+B(C语言)
- 安装ubuntu14.04.2集群环境下的cloudera5.4.7+CDH5
- eclipse添加library错误
- linux删除用户
- Java基础增强-增强for循环,装箱,map类型的操作
- 写给那些傻傻的,想做服务器开发的应届生
- HDU2096
- java单例模式详解
- 创建自定义的扩展点
- iOS 开发流程笔记(四)
- POJ 3187 Backward Digit Sums(DFS)
- 遗传算法优点(论文可用)
- 如何将github上的项目部署到oschina
- 椭圆轨迹计算方法
- 身份认证之密码存储