两个大整数加法
来源:互联网 发布:刘阳java 编辑:程序博客网 时间:2024/05/16 01:50
题目地址:http://acm.cs.ecnu.edu.cn/problem.php?problemid=1001
#include<stdio.h>#include<string.h>#define max 505int aa[max];int bb[max];int lenaa;int lenbb;int t; //记录进位int main(){void plus();void print();void change(char *a,char *b) ;char a[max];char b[max];while(scanf("%s%s",a,b)!=EOF){t=0;if(strlen(a)>=strlen(b)) //若a的长度比b长,那么aa中放a,反之,放b{change(a,b);}else{change(b,a);}plus();print();}return 0;}void change(char *a,char *b) //将char转换为int{ //a的位数比b的大,aa中放的是位数比较大那个数据int i;lenaa=strlen(a);lenbb=strlen(b);for(i=0;i<strlen(a);i++){aa[i]=a[i]-'0';}for(i=0;i<strlen(b);i++){bb[i]=b[i]-'0';}}void plus(){int i,j;i=lenaa-1;j=lenbb-1;while(i>=0&&j>=0){if(aa[i]+bb[j]+t>=10){aa[i]=aa[i]+bb[j]+t-10;t=1;}else{aa[i]=aa[i]+bb[j]+t;t=0;}i--;j--;}while(i>=0){if(aa[i]+t>=10){aa[i]=aa[i]+t-10;t=1;}else{aa[i]=aa[i]+t;t=0;}i--;}}void print() //输出和{int i;if(t==1){printf("1");}for(i=0;i<lenaa;i++){printf("%d",aa[i]);}printf("\n");}
- 两个大整数加法
- 两个大整数相加—高精度加法
- 字符数组实现两个大整数的加法
- Java模拟两个大整数的加法、乘法、除法
- 计算两个1000位大整数的加法
- 大整数加法
- 大整数加法
- 高精度 大整数加法
- 大整数加法
- 大整数加法
- 大整数加法
- 大整数加法
- 大整数加法计算
- zoj1292大整数加法
- 大整数加法
- 大整数加法
- 大整数加法函数
- 大整数加法
- 屏蔽国内或者国外ip的代码 GeoIP
- 页面开发与兼容性有关设置的问题
- gis and openlayers
- 看见比较好的速度导出excel的方法(sql原创)
- ibatis调用存储过程
- 两个大整数加法
- hbase region, store, storefile和列簇,的关系
- This example uses the Delete method to remove a specified record from a Recordset.
- 创建Annotation要素类(Creating annotation and dimension feature classes)
- Android各种基础知识(一)
- android布局属性详解
- 用Hibernate进行对象的持久化
- 用SIP来生成C/C++/Qt库的Python绑定(二)
- makefile