fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int convrt(char inp){ //string to int
  5. return inp-48;
  6. }
  7. string count(string q, string w){
  8. reverse(q.begin(),q.end());
  9. reverse(w.begin(),w.end());
  10. if (q.length()>w.length()){
  11. int longest = q.length() - w.length();
  12. for (int i=0;longest>i;++i){
  13. w+="0";
  14. }
  15. }
  16. else{
  17. int longest = w.length() - q.length();
  18. for (int i=0;longest>i;++i){
  19. q+="0";
  20. }
  21. }
  22. int length = q.length();
  23. string outp;
  24. bool carry = false;
  25. for (int i=0;length>i;++i){
  26. int param=0;
  27. if (i<q.length()) param += convrt(q[i]) + convrt(w[i]);
  28. (carry) ? param++ : param=param;
  29. if (param<10){
  30. outp+= param+48;
  31. carry=false;
  32. }
  33. else{
  34. carry=true;
  35. param%=10;
  36. outp+=param+48;
  37. length++;
  38. }
  39. }
  40. reverse(outp.begin(),outp.end());
  41. while(outp[0]=='0'){
  42. outp.erase(0,1);
  43. }
  44. return outp;
  45. }
  46.  
  47.  
  48. int main(){
  49. int tc;cin>>tc;
  50. for (int i=0;tc>i;++i){
  51. (i!=0)?cout<<endl:cout;
  52. int length;cin>>length;
  53. string q="0";
  54. for (int j=0;length>j;++j){
  55. string qq,ww;
  56. cin>>qq>>ww;
  57. q = count(q,qq);
  58. q = count(q,ww);
  59. if (j+1!=length)q+="0";
  60. }
  61. cout<<q<<endl;
  62. }
  63. }
Success #stdin #stdout 0s 16064KB
stdin
2
4
0  4
4  2
6  8
3  7
3
3  0
7  9
2  8
stdout
4750

470