POJ 1503 Integer Inquiry
来源:互联网 发布:大数据来源于 编辑:程序博客网 时间:2024/05/17 06:15
高精度加法。水。
给一长串的数字,加起来就好。
#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<stack>#include<iostream>#include<list>#include<set>#include<cmath>#define INF 0x7fffffff#define eps 1e-6#define LL long long#define CLRi for(int i=0;i<n;i++)#define CLRj for(int j=0;j<n;j++)#define CLRk for(int k=0;k<n;k++)#define debug puts("==fuck==");#define acfun std::ios::sync_with_stdio(false)#define Nmax 1001#define Mmax 1001*1001using namespace std;char s1[1001],s2[1001];void Add(){ stack<int>a; stack<int>b; stack<int>out; for(int i=0; s1[i]!='\0'; i++) a.push(s1[i]-'0'); for(int i=0; s2[i]!='\0'; i++) b.push(s2[i]-'0'); int na,nb,c=0; while(!a.empty()||!b.empty()) { if(!a.empty()) { na=a.top(); a.pop(); } else na=0; if(!b.empty()) { nb=b.top(); b.pop(); } else nb=0; c+=na+nb; out.push(c%10); c/=10; } while(c) { out.push(c%10); c/=10; } int k=0; while(!out.empty()) { int tmp=out.top(); out.pop();// printf("%d",tmp); s1[k++]=tmp+'0'; } s1[k]='\0';}int main(){ s1[0]='0';s1[1]='\0'; while(scanf("%s",s2)!=EOF) { if(strcmp(s2,"0")==0)break; Add(); } puts(s1);}
0 0
- POJ – 1503 Integer Inquiry Integer Inquiry
- POJ 1503 Integer Inquiry
- poj 1503 Integer Inquiry
- POJ 1503 Integer Inquiry
- poj 1503 Integer Inquiry
- POJ 1503 Integer Inquiry
- POJ 1503 Integer Inquiry
- POJ---1503 Integer Inquiry
- poj 1503 Integer Inquiry
- POJ 1503 Integer Inquiry
- POJ 1503Integer Inquiry
- POJ 1503 Integer Inquiry
- POJ 1503 Integer Inquiry
- poj 1503 Integer Inquiry
- POJ-1503 Integer Inquiry
- POJ 1503 Integer Inquiry
- POJ 1503 Integer Inquiry
- poj 1503 Integer Inquiry
- Web_PHP_DedeCMS_自定义函数汇总;
- java单例模式案例
- iphone 配件通信
- hdu1074 doing homework
- opencv xml读写
- POJ 1503 Integer Inquiry
- 在线调试工具集锦
- android sdk---radioGroup用法实例
- Flex 添加效果的两种方法
- vnc 相关
- hdu 4366 Successor 线段树
- 发现一个grails中判断domain保存(save)不成功的方法
- hdoj.1163 Eddy's digital Roots 20140813
- 拼音分词