Advertisement
erfanul007

UVa 424

Feb 14th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef unsigned long long int ull;
  5. typedef long long int ll;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int > pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define sc scanf
  14. #define pf printf
  15. #define sci(n) scanf("%d",&n)
  16. #define scl(n) scanf("%lld",&n)
  17. #define scd(n) scanf("%lf",&n)
  18. #define scs(s) scanf("%s",s)
  19. #define pfi(n) printf("%d",n)
  20. #define pfl(n) printf("%lld",n)
  21. #define pff(n) cout<<n
  22. #define line printf("\n")
  23. #define spc printf(" ")
  24. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  25. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  26. #define cspf(i) printf("Case %d: ", i)
  27. #define pb push_back
  28. #define mp make_pair
  29. #define ff first
  30. #define ss second
  31. #define all(v) v.begin(),v.end()
  32. #define rall(v) v.rbegin(),v.rend()
  33. #define read() freopen("input.txt", "r", stdin)
  34. #define write() freopen("output.txt", "w", stdout)
  35. /// Constants
  36. #define eps 1e-9
  37. #define PI acos(-1.0) // 3.1415926535897932
  38. #define MAX 1000009
  39.  
  40. vector<string>num;
  41. int mx=0;
  42.  
  43. void cal()
  44. {
  45. int carry=0,temp,mod,i=0,j;
  46. char digit;
  47. string sum;
  48. for(i=0;i<mx;i++){
  49. temp=carry;
  50. for(j=0;j<num.size();j++){
  51. if(i<num[j].size()){
  52. temp=temp+(num[j][i]-'0');
  53. }
  54. }
  55. mod=temp%10;
  56. sum.insert(sum.begin()+i,mod+'0');
  57. carry=temp/10;
  58. }
  59. if(!mx)
  60. sum.insert(sum.begin()+i,'0');
  61. while(carry){
  62. mod=carry%10;
  63. sum.insert(sum.begin()+i,mod+'0');
  64. i++;
  65. carry/=10;
  66. }
  67. reverse(sum.begin(),sum.end());
  68. cout<<sum<<endl;
  69. }
  70.  
  71. int main()
  72. {
  73. read();
  74. write();
  75. string s;
  76. while(true){
  77. cin>>s;
  78. if(s.size()==1 && s[0]-'0'==0) break;
  79. int sz=s.size();
  80. if(sz>mx) mx=sz;
  81. reverse(s.begin(),s.end());
  82. num.push_back(s);
  83. }
  84. cal();
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement