#include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s1, s2, s3; cin>>s1>>s2; int ss1 = s1.size(), ss2 = s2.size(); int z = 0; for(; ss1*ss2 != 0; ss1--, ss2--) { z += s1[ss1 - 1] + s2[ss2 - 1] - 96; s3 = (char)(z%10+'0') + s3; z /= 10; } for(; ss1 != 0; ss1--) { z+= s1[ss1 - 1] - 48; s3 = (char)(z%10+'0') + s3; z /= 10; } for(; ss2 != 0; ss2--) { z+= s2[ss2 - 1] - 48; s3 = (char)(z%10+'0') + s3; z /= 10; } s3 = (z==1?('1'+s3):s3); cout<<s3; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s1, s2, s3; cin>>s1>>s2; int ss1 = s1.size(), ss2 = s2.size(); int z = 0; for(; ss1*ss2 != 0; ss1--, ss2--) { z += s1[ss1 - 1] + s2[ss2 - 1] - 96; s3 = (char)(z%10+'0') + s3; z /= 10; } for(; ss1 != 0; ss1--) { z+= s1[ss1 - 1] - 48; s3 = (char)(z%10+'0') + s3; z /= 10; } for(; ss2 != 0; ss2--) { z+= s2[ss2 - 1] - 48; s3 = (char)(z%10+'0') + s3; z /= 10; } s3 = (z==1?('1'+s3):s3); cout<<s3; return 0; } |