#include <iostream> using namespace std; int main(){ string W; cin>>W; string Q; cin>>Q; W = '0' + W; W = '0' + W; Q = '0' + Q; Q = '0' + Q; while(W.size() != Q.size()){ if(W.size() > Q.size()){ Q = '0' + Q; } if(Q.size() > W.size()){ W = '0' + W; } } int tab1[Q.size()]; int tab[W.size()]; for(int i = 0; i < W.size();i++){ tab[i] = W[i] - '0'; tab1[i] = Q[i] - '0'; } int p = 0; for(int i = W.size() - 1; i > 0;i--){ tab[i] = tab[i] + tab1[i]; tab[i] += p; p = tab[i] / 10; tab[i] %= 10; } int z = 0; while(tab[z] == 0){ z++; } for(int i = z; i < W.size();i++){ cout<<tab[i]; } }
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 36 37 38 39 40 41 42 43 44 | #include <iostream> using namespace std; int main(){ string W; cin>>W; string Q; cin>>Q; W = '0' + W; W = '0' + W; Q = '0' + Q; Q = '0' + Q; while(W.size() != Q.size()){ if(W.size() > Q.size()){ Q = '0' + Q; } if(Q.size() > W.size()){ W = '0' + W; } } int tab1[Q.size()]; int tab[W.size()]; for(int i = 0; i < W.size();i++){ tab[i] = W[i] - '0'; tab1[i] = Q[i] - '0'; } int p = 0; for(int i = W.size() - 1; i > 0;i--){ tab[i] = tab[i] + tab1[i]; tab[i] += p; p = tab[i] / 10; tab[i] %= 10; } int z = 0; while(tab[z] == 0){ z++; } for(int i = z; i < W.size();i++){ cout<<tab[i]; } } |