博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ 1002
阅读量:6546 次
发布时间:2019-06-24

本文共 2356 字,大约阅读时间需要 7 分钟。

A + B Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 124589    Accepted Submission(s): 23993

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
 

 

1 #include 
2 using namespace std; 3 4 void sum(char (&a)[1001],char (&b)[1001]); 5 int main() 6 { 7 int T, count_T; 8 char a[1001], b[1001]; 9 cin >> T;10 for(count_T=1; count_T <= T; count_T++) 11 {12 cin >> a >> b;13 14 if(count_T==1) 15 {16 cout << "Case " << count_T << ":" << endl;17 }18 else 19 {20 cout << "\nCase " << count_T << ":" << endl;21 }22 23 cout << a << " + " << b << " = ";24 25 sum(a,b);26 }27 return(0);28 }29 void sum(char (&a)[1001],char (&b)[1001])30 {31 char c[1002]; 32 int la, lb;33 la=strlen(a)-1;34 lb=strlen(b)-1;35 int i;36 int flag=0;37 for(i=0;la>=0 && lb>=0;la--,lb--,i++)38 {39 flag+=(a[la]-'0')+(b[lb]-'0');40 c[i]=flag%10;41 flag/=10;42 }43 for(la=la;la>=0;la--,i++)44 {45 flag+=(a[la]-'0');46 c[i]=flag%10;47 flag/=10;48 }49 for(lb=lb;lb>=0;lb--,i++)50 {51 flag+=(b[lb]-'0');52 c[i]=flag%10;53 flag/=10;54 }55 if(flag)56 {57 c[i]=flag;58 i++;59 }60 for(i--;i>=0;i--)61 {62 cout<<(char)(c[i]+'0');63 }64 cout<

 

转载地址:http://umedo.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
MariaDB集群Galera Cluster的研究与测试
查看>>
SONY控制键盘JX-11,EVI-D70P控制方案
查看>>
Spring AOP 之二:Pointcut注解表达式
查看>>
在普通台式机上搭建服务器虚拟化架构Esxi平台
查看>>
电话线路 30B+D 名词解释
查看>>
吉炬消费系统软件输入密码后无法打开软件界面故障处理
查看>>
Hibernate学习系列————注解一对多双向实例
查看>>
Cannot load from mysql.proc
查看>>
网络运维之 EX4200消除var分区使用过高的告警
查看>>
【最好的流程是没有流程】
查看>>
Apache Thrift 教程
查看>>
Python Epoll
查看>>
AS3歌词同步详解
查看>>
单例模式
查看>>
Linux环境NetBeans字体通用抗据齿解决方法
查看>>
Eclipse的花括号(brace)的输入偏好问题
查看>>
工作记录
查看>>
cucumber-api安装与试用
查看>>
计算硬件简史
查看>>