还是A+B问题,不过是大数A+B,T组输入,样例输入 2 1 2 112233445566778899 998877665544332211 样例输出 Case 1: 1 + 2 = 3 Case 2
来源:互联网 发布:python 遗传算法 股票 编辑:程序博客网 时间:2024/06/07 01:45
#include<stdio.h>
#include<string.h>
int main()
{
char str1[1001],str2[1001];
int t,j=0;
scanf("%d",&t);
while(t--)
{
scanf("%s%s",str1,str2);
int a[1001]= {0},b[1001]= {0},c[1001]= {0},i;
int m,n,max1=0;
m=strlen(str1);
n=strlen(str2);
max1=(m>n?m:n);//m,n大小,输出较大的数的长度
for(i=0; i<max1; i++)
{
a[m-i-1]=str1[i]-'0';
b[n-i-1]=str2[i]-'0';
}
for(i=0; i<max1; i++)
c[i]=a[i]+b[i];
for(i=0; i<max1; i++)
{
c[i+1]+=c[i]/10;
c[i]=c[i]%10;
}
printf("Case %d:\n",++j);
printf("%s + %s = ",str1,str2);
//倒序输出和;
if(c[max1]!=0)
{
for(i=max1; i>=0; i--)
printf("%d",c[i]);
}
else
{
for(i=max1-1; i>=0; i--)
printf("%d",c[i]);
}
printf("\n");
}
return 0;
}
点击打开链接 #include<string.h>
int main()
{
char str1[1001],str2[1001];
int t,j=0;
scanf("%d",&t);
while(t--)
{
scanf("%s%s",str1,str2);
int a[1001]= {0},b[1001]= {0},c[1001]= {0},i;
int m,n,max1=0;
m=strlen(str1);
n=strlen(str2);
max1=(m>n?m:n);//m,n大小,输出较大的数的长度
for(i=0; i<max1; i++)
{
a[m-i-1]=str1[i]-'0';
b[n-i-1]=str2[i]-'0';
}
for(i=0; i<max1; i++)
c[i]=a[i]+b[i];
for(i=0; i<max1; i++)
{
c[i+1]+=c[i]/10;
c[i]=c[i]%10;
}
printf("Case %d:\n",++j);
printf("%s + %s = ",str1,str2);
//倒序输出和;
if(c[max1]!=0)
{
for(i=max1; i>=0; i--)
printf("%d",c[i]);
}
else
{
for(i=max1-1; i>=0; i--)
printf("%d",c[i]);
}
printf("\n");
}
return 0;
}
阅读全文
1 0
- 还是A+B问题,不过是大数A+B,T组输入,样例输入 2 1 2 112233445566778899 998877665544332211 样例输出 Case 1: 1 + 2 = 3 Case 2
- 学习C语言的第一题 输入 输入两个数,a,b 输出 输出a+b的值 样例输入 2 3 样例输出 5
- int func(int a) { int b; switch(a) { case 1: 30; case 2: 20; case 3: 16; default: 0 } return b; }
- 输入2个正整数A,B,求A与B的最大公约数。 Input 2个数A,B,中间用空格隔开。(1<= A,B <= 10^9) Output 输出A与B的最大公约数。
- 输入两个数A,B,输出A+B的值2(用数字控制组数)
- hdu 1089 a+b问题1 多组输入 20140722
- PB中 A下拉框选择1 ,B输入框不能用,A下拉框选择2 ,B输入框能用
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。Java实现
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+3+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- java中Memcached的使用(包括与Spring整合)
- 二叉树的先序、中序和后序遍历,递归与非递归方式实现。
- Java关键字this、super使用总结
- 半边数据结构讲解
- 利用java编写百钱买百鸡
- 还是A+B问题,不过是大数A+B,T组输入,样例输入 2 1 2 112233445566778899 998877665544332211 样例输出 Case 1: 1 + 2 = 3 Case 2
- java多线程 run() 与start()方法的区别
- Sql Server2008服务远程过程调用失败
- CentOS7 REDIS数据库单机版配置
- NYOJ H. 括号配对问题
- install PyQt4
- SVM算法 理论
- python基础-random、os模块、异常处理模块
- unity5.X AB包打包插件研究