A + B Problem II 1002 hdu 大数模板
题目http://acm.hdu.edu.cn/showproblem.php?pid=1002 大数相加模板(头文件string) string add(string s1,string s2)? 1002代码 #include<iostream> #include<cstring> using namespace std; string add(string s1,string s2) { ??? ? ?? int j,lb; ??? string max,min; ? ??? max=s1;min=s2; ??? if(s1.length()<s2.length()) {max=s2;min=s1;} ??? la=max.size();lb=min.size(); ??? l=la-1; ??? for(j=lb-1;j>=0;j--,l--) max[l] += min[j]-'0'; ? ??? for(j=la-1;j>=1;j--) if(max[j]>'9'){max[j]-=10;max[j-1]++;} ??? if(max[0]>'9') {max[0]-=10;max='1'+max;} ??? return max; } int main() { ?? ?int t,i=1; ?? ?cin>>t; ?? ?string a,b; ?? ?while(t--) ?? ?{ ?? ??? ? ?? ??? ?cin>>a>>b; ?? ??? ?cout<<"Case "<<i++<<":"<<endl; ?? ??? ?cout<<a<<" + "<<b<<" = "<<add(a,b)<<endl; ?? ??? ?if(t!=0) ?? ??? ?cout<<endl; ?? ?} ?? ? ?? ?return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |