练习系统 实验三 大整数加法
2017-03-06 15:18
176 查看
当前编程题:实验三 大数、枚举问题(16级)---大整数加法 |
3. | 问题描述 求两个不超过200位的非负整数的和。 输入形式 有两行,每行是一个不超过200位的非负整数,没有多余的前导0。 输出形式 一行,即相加后的结果。结果里不能有多余的前导0,即如果结果是342,那么就不能输出为0342。 样例输入 22222222222222222222 33333333333333333333 样例输出 55555555555555555555 昨天不知道是电脑抽筋了还是这两个编译软件抽筋了 反正就是不会判断了 那么正确的代码 竟然不通过 哎 昨天很崩溃 #include<stdio.h> #include<string.h> int main() { char aa[200],bb[200]; int cc[200],i,j,lenth1,lenth2; memset(cc,0,sizeof(cc)); gets(aa); gets(bb); // puts(aa); // puts(bb); lenth1=strlen(aa); lenth2=strlen(bb); if(lenth1>=lenth2) { for(i=0;i<lenth1;i++) { aa[lenth1-1-i]-='0'; bb[lenth2-1-i]-='0'; if(lenth2-1-i>=0) { cc[i]+=aa[lenth1-1-i]+bb[lenth2-1-i]; } else { cc[i]+=aa[lenth1-1-i]; } } } else { for(i=0;i<lenth2;i++) { aa[lenth1-1-i]-='0'; bb[lenth2-1-i]-='0'; if(lenth1-1-i>=0) { cc[i]+=aa[lenth1-1-i]+bb[lenth2-1-i]; } else { cc[i]+=bb[lenth2-1-i]; } } } for(j=0;j<i;j++) { if(cc[j]>=10) { cc[j+1]+=cc[j]/10; cc[j]=cc[j]%10; } // printf("%d ",cc[j]); } // printf("\n"); if(cc[j]>0) { i++; } for(j=0;j<i;j++) { aa[j]=cc[i-j-1]+'0'; } aa[j]='\0'; puts(aa); return 0; } |
相关文章推荐
- 练习系统 实验三 大整数除法
- 练习系统 实验三 求大整数的阶乘
- 练习系统 实验三 大整数乘法
- 任意长整数加法运算(C++)实验文档
- 如果系统要使用超大整数(超过long长度范围),请你设计一个数据结构来存储这种超大型数字以及设计一种算法来实现超大整数加法运算
- 练习系统 实验二 All in All
- 练习系统 实验一 谁拿了最多的奖学金
- 练习系统 实验一 简单密码
- C/C++程序算法小练习--大整数加法
- 练习系统 实验四 八皇后(枚举法)
- 练习系统 实验二 不吉利日期
- 练习系统 实验二 计算2的N次方
- 练习系统 实验四 迷宫
- Java程序练习-长整数加法运算
- 练习系统 实验三 菲波那契数列
- 练习系统 实验二 循环数
- 练习系统 实验一 垂直直方图
- 【蓝桥杯练习系统】 基础练习 查找整数
- 如果系统要使用超大整数(超过long长度范围),请你设计一个数据结构来存储这种超大型数字以及设计一种算法来实现超大整数加法运算)
- 练习系统 实验一 密码