HDU 1047 Integer Inquiry 可做大数模板
2015-03-23 15:57
204 查看
#include <stdio.h> //**********************************************学习了 #include <string> //有讲究,加.h就错了 为什么呢 #include <iostream> using namespace std; string add(string str1,string str2) { string str; int len1=str1.length(); int len2=str2.length(); if(len1<len2) { for(int i=1;i<=len2-len1;i++) str1="0"+str1; //这里注意 } else { if(len1>len2) for(int i=1;i<=len1-len2;i++) str2="0"+str2; } int temp,cf=0; len1=str1.length();//这句要加上 for(int i=len1-1;i>=0;i--) { temp=str1[i]-'0'+str2[i]-'0'+cf; cf=temp/10; temp%=10; str=char(temp+'0')+str; //这里 } if(cf) str=char(cf+'0')+str; return str; } int main() { int N; scanf("%d",&N); while (N--) { string str1; string sum="0"; while(cin>>str1) //和用数组是差不多的 { if(str1=="0") break; sum=add(sum,str1); } cout<<sum<<endl; if(N>0) cout<<endl; } return 0; }
相关文章推荐
- hdu 2222 AC自动机(可做模板)
- HDU5351大数模板加斐波那契
- hdu_1041(Computer Transformation) 大数加法模板+找规律
- HDU 5429 Geometric Progression(大数模板)——BestCoder Round #54(div.1 div.2)
- HDU 1023 Train Problem II 卡特兰数 及完全大数模板
- HDU 1041 递推 + 大数模板
- hdu 1134 大数模板
- HDU 5475 An easy problem(用大数模板,你就上当了)——2015 ACM/ICPC Asia Regional Shanghai Online
- <模板> Hdu 1402 A * B Problem Plus 大数乘法
- HDU 1134 大数取模 使用大数模板
- hdu 1023+1030+1134 卡特兰数+大数模板处理
- hdu 4927 Series 1 (大数模板加减乘除)
- hdu 5429 Geometric Progression (等比数列判定+大数模板)
- hdu1002 A + B Problem II(大数加法一)模板
- A + B Problem II 1002 hdu 大数模板
- hdu 1002 A + B Problem II 万能大数模板再次成功应用
- HDU 5569 长度为n的上升子序列个数d (大数模板+DP)
- 大数模板 hdu 4759 Poker Shuffle
- HDU 1402 A * B Problem Plus (大数乘法,FFT模板题)
- HDU 1297 Children’s Queue(含整型大数模板)