欢迎使用CSDN-markdown编辑器
来源:互联网 发布:武藏点胶机编程 编辑:程序博客网 时间:2024/05/21 19:39
A + B Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 383304 Accepted Submission(s): 74489
Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
Output
For each test case, you should output two lines. The first line is “Case #:”, # means the number of the test case. The second line is the an equation “A + B = Sum”, Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
Sample Input
2
1 2
112233445566778899 998877665544332211
Sample Output
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
Author
Ignatius.L
可以说是很耿直的做法了······
#include<stdio.h>#include<iostream>#include<string.h>using namespace std;string s1,s2;int sum[1005];int t,l1,l2;int main(){ cin>>t; for(int i=1;i<=t;i++){ cin>>s1>>s2; l1=s1.size(); l2=s2.size(); int p=0; int l=0; for(;l1>0||l2>0;l1--,l2--){ if (l1>0&&l2>0){ //s1和s2都有第l位 sum[l]=(((s1[l1-1]-'0')+(s2[l2-1])-'0')+p)%10; p=((s1[l1-1]-'0')+(s2[l2-1]-'0')+p)/10; }else if(l1<=0){ //s1有第l位 sum[l]=(((s2[l2-1])-'0')+p)%10; p=((s2[l2-1]-'0')+p)/10; }else{ //s2有第l位 sum[l]=((s1[l1-1]-'0')+p)%10; p=((s1[l1-1]-'0')+p)/10; } l++; } cout<<"Case "<<i<<":"<<endl<<s1<<" + "<<s2<<" = "; if(p>0) cout<<'1'; //注意最后第一位的进位,否则和我一样一直wa就不好玩了 for(int m=l-1;m>=0;m--) cout<<sum[m]; cout<<endl; if (i!=t) cout<<endl; } return 0; }
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器
- Android 仿照第三方app 将自己APP显示在打开列表中
- 搭建ssm框架
- [Sensor]--BMI160-加速度计、陀螺仪传感器
- 进程同步之信号量机制(笔记三)
- Oracle SELECT INTO 和 INSERT INTO SELECT 两种表复制语句详解
- 欢迎使用CSDN-markdown编辑器
- ROCA漏洞卷土重来,可致各种设备密钥泄漏
- 2基于opencv的多通道分离和合并
- scrapy绕过反爬虫
- 《java web 设计模式之道》读后感之代理模式
- github莫名奇妙加载样式失败
- php通过socket,以SMTP发送邮件
- Android | 单例
- JVM知识点总览