fork(2) download
  1. #include <iostream>
  2. int main()
  3. {
  4. int amount;
  5. std::cin>>amount;
  6. while(amount--)
  7. {
  8. char one[1000],two[1000];
  9. std::string result="";
  10. std::cin>>one>>two;
  11. int lengthOne,lengthTwo;
  12. for(lengthOne=0;one[lengthOne]!=0;++lengthOne);
  13. for(lengthTwo=0;two[lengthTwo]!=0;++lengthTwo);
  14. if(lengthOne>lengthTwo)
  15. {
  16. for(int j=lengthTwo-1,i=lengthOne-1;i>=0;--i,--j)
  17. {
  18. if(j>=0){two[i]=two[j];++lengthTwo;}
  19. else two[i]='0';
  20. }
  21. two[lengthOne]=0;
  22. lengthTwo=lengthOne;
  23. }
  24. if(lengthOne<lengthTwo)
  25. {
  26. for(int j=lengthOne-1,i=lengthTwo-1;i>=0;--i,--j)
  27. {
  28. if(j>=0)one[i]=one[j];
  29. else one[i]='0';
  30. }
  31. one[lengthTwo]=0;
  32. lengthOne=lengthTwo;
  33. }
  34. int rest=0;
  35. for(int i=lengthOne-1;i>=0;--i)
  36. {
  37. if((int)one[i]%48+(int)two[i]%48+rest<10){result+=(char)((int)one[i]%48+(int)two[i]%48+rest)+'0';rest=0;}
  38. else {result+=(char)(((int)one[i]%48+(int)two[i]%48+rest)%10)+'0';
  39. rest=((int)one[i]%48+(int)two[i]%48+rest)/10;}
  40. }
  41. for(int i=result.length()-1;i>=1;--i){if(result[i]=='0')result.pop_back();else break;}
  42. for(int i=result.length()-1;i>=0;--i){std::cout<<result[i];}
  43. std::cout<<std::endl;
  44. }
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 16064KB
stdin
3
363636363636 6363636364
1212121212 8787878787878788
1234567 11118765433
stdout
370000000000
8787880000000000
11120000000