/********************************
* 日期:2011-1-19
* 作者:sjf0115
* 题号:杭电1002
* 题目:A + B Problem II
* 结果:AC
********************************/
#include<stdio.h>
#include<string.h>
int main()
{
char a1[1100],b1[1100];
int T;
while(scanf("%d",&T)!=EOF)
{
int i1,i,j,k,k1,La,Lb,t,L;
for(i1=1;i1<=T;i1++)
{
int a[1100]={0},b[1100]={0},c[1100]={0};
scanf("%s%s",&a1,&b1);
La=strlen(a1);
Lb=strlen(b1);
printf("Case %d:\n",i1);
for(i=0;i<La;i++)//输出第一个数
{
printf("%c",a1[i]);
}
printf(" + ");
for(i=0;i<Lb;i++)//输出第二个数
{
printf("%c",b1[i]);
}
printf(" = ");
for(j=La-1,t=0;j>=0;j--,t++)//反序
{
a[t]=a1[j]-'0';
}
for(k=Lb-1,t=0;k>=0;k--,t++)//反序
{
b[t]=b1[k]-'0';
}
L=(La>=Lb?La:Lb);
for(i=0;i<=L-1;i++)//加法运算
{
c[i]=(a[i]+b[i])+c[i];
if(c[i]>=10)
{
c[i]=c[i]%10;
c[i+1]++;
}
}
if(c[L]!=0)
{
L++;
}
for(i=L-1;i>=0;i--)//输出运算结果
{
printf("%d",c[i]);
}
printf("\n");
if(i1!=T)
{
printf("\n");
}
}
}
return 0;
}
分享到:
相关推荐
在编程的时候供大家参考,希望各位参加 acm的同学好好努力,能够取得好成绩
Description Calculate a+b Input Two integer a,b (0<=a,b) Output Output a+b Sample Input 1 2 Sample Output 3
可以计算任意位数的加法,C++实现,精度可达100位
下载超过3次或对应题解文章点赞超过1个便开放免费下载!
FZYZOJA+B Problem.cpp
洛谷题解:P1001-A+B Problem
A+B的c语言表示方法.很简单的一个例子仅供参考
输入A和B,求出A+B的值
#include using namespace std; int main() { int a,b; cin>>a>>b; cout<<a+b; }
杭电ACM第1001题的代码。这个A+B PROBLEM的变形。初学者只要习惯了就好
Problem Description 话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫“大明”。 这时他已经不是那个只会做100以内加法的那个“小明”了,现在他甚至会任意长度的正小数的加法。 现在,给你...
NULL 博文链接:https://weitch.iteye.com/blog/1006774
ACM杭电Problem 1002 C++程序 大数相加问题,注意输出的限制
具体题目在我的博文当中
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) which means the number of test cases. Then T lines follow, each ...
Uva 100 ,问题是The 3n+1 probelm ,可以ac的代码
北大POJ1207-The 3n + 1 problem 解题报告+AC代码
UVA 100题答案
《英语学习工具书总汇》作者:多人,多本英语工具书的集合!
Data+Abstraction+and+Problem+Solving+with+C+++3+Ed