fork(1) download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n;
  8. cin>>n;
  9. for (int i=0; i<n; i++)
  10. {
  11. string x,y;
  12. cin>>x>>y;
  13.  
  14. int lx,ly;
  15. lx=x.length();
  16. ly=y.length();
  17. char xTab [1024];
  18. strcpy(xTab,x.c_str());
  19. char yTab [1024];
  20. strcpy(yTab,y.c_str());
  21.  
  22. int dlugosc_wyniku=(lx>=ly?lx:ly);
  23. if (((xTab[0]-'0')+(yTab[0]-'0'))>9) dlugosc_wyniku++;
  24. // cout<<"dl_w: "<<dlugosc_wyniku<<endl;
  25. int k=dlugosc_wyniku;
  26. int n=0,z=0;
  27. int f[dlugosc_wyniku];
  28. while (true)
  29. {
  30. int a= xTab[lx-1] - '0';
  31. int b= yTab[ly-1] - '0';
  32. if (lx-1<0)a=0;
  33. if (ly-1<0)b=0;
  34. z=a+b+n;
  35. n=0;
  36. if ((lx-1<0)&&(ly-1<0)&&z==0) break;
  37. while (z>9)
  38. {
  39. n++;
  40. z-=10;
  41. }
  42. lx--;
  43. ly--;
  44. f[dlugosc_wyniku-1]=z;
  45. dlugosc_wyniku--;
  46. // cout<<" liczba "<<dlugosc_wyniku+1<<" wynosi "<<z<<endl;
  47. }
  48. for (int j=0; j<=k-1; j++)
  49. {
  50. cout<<f[j];
  51. }
  52. cout<<endl;
  53. }
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0s 15240KB
stdin
3
172 3498
123456789 987654321
1234567890123456789 12123343456567878909
stdout
3670
1111111110
13357911346691335698