Big vs Big(链表)
来源:互联网 发布:登陆艇升级数据经验值 编辑:程序博客网 时间:2024/06/07 03:06
【题目描述】
Calculate the addtion of any two positive big integers.
Requirements:
Test data can be more than 64 digits, therefore you MUST use a linked list to store an integer (any big).
【输入】
The first line contains the number of test cases, N.
In the next 2*N lines, each line contains a string of number.
【输出】
Out put N lines. Each line represent the sum of A and B.
【我的程序】
#include <stdlib.h>#include <iostream>using namespace std;typedef struct node{ int num; node *av; }* wei;wei newWei(int x){ wei y=(wei)malloc(sizeof(node)); y->num=x; y->av=NULL; return y;}int main(){ int n; char ch; cin>> n; cin.get(); for (int i=0;i<n;i++) { wei x=newWei(cin.get()-'0'); while ((ch=cin.get())!='\n'){ wei p=newWei(ch-'0'); p->av=x; x=p; } wei y=newWei(cin.get()-'0'); while ((ch=cin.get())!='\n'){ wei p=newWei(ch-'0'); p->av=y; y=p; } wei re=newWei(x->num+y->num); int jw=(re->num)/10; re->num%=10; x=x->av; y=y->av; while (x!=NULL && y!=NULL) { wei p=newWei(x->num+y->num+jw); jw=(p->num)/10; p->num%=10; p->av=re; re=p; x=x->av; y=y->av; } while (y!=NULL) { wei p=newWei(y->num+jw); jw=p->num/10; p->num%=10; p->av=re; re=p; y=y->av; } while (x!=NULL) { wei p=newWei(x->num+jw); jw=p->num/10; p->num%=10; p->av=re; re=p; x=x->av; } if (jw>0) cout<< jw; while (re!=NULL){ cout<< re->num; re=re->av; } cout<< endl; } return 0;}
0 0
- Big vs Big(链表)
- big
- Little Endian vs. Big Endian
- little endian VS big endian
- Big Endian vs. Little Endian
- big endian vs little endian
- Little endian vs Big endian
- Professor Hendryx vs. Big Coal
- Big Number(阶乘)
- Big Number(1018)
- (UVA)Big Chocolate
- Big Number(1212)
- HDU1018(Big Number)
- Big Data (1)
- Big Data (2)
- big (Trie)
- My Big Big Blog
- big big world中文歌词
- UILable,UIButton字体加粗
- 乱码终极解决大全
- Android初试--Android中的ContentProvider(3)
- httpd.conf配置后php7,出现apache无法启动的现象
- 递归写法总结
- Big vs Big(链表)
- 机器学习实战(5)--SVM(Support vector machine)(二)
- struts2不显示.do .action 后缀
- 关于在c#中如何遍历listbox中选中项的问题
- 实现ViewPager懒加载的三种方法
- 集合框架--List常用子类
- C提高——const专题
- 获取网络状态
- fast-rcnn配置运行VGG16.caffemodel和VGG_CNN_M_1024.v2.caffemodel(Ubuntu14.04)