Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef unsigned long long int ull;
- typedef long long int ll;
- typedef vector<int> vi;
- typedef vector<ll> vll;
- typedef vector<vi> vvi;
- typedef pair<int,int > pii;
- typedef vector< pii > vpii;
- typedef set<int> sti;
- #define sc scanf
- #define pf printf
- #define sci(n) scanf("%d",&n)
- #define scl(n) scanf("%lld",&n)
- #define scd(n) scanf("%lf",&n)
- #define scs(s) scanf("%s",s)
- #define pfi(n) printf("%d",n)
- #define pfl(n) printf("%lld",n)
- #define pff(n) cout<<n
- #define line printf("\n")
- #define spc printf(" ")
- #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
- #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
- #define cspf(i) printf("Case %d: ", i)
- #define pb push_back
- #define mp make_pair
- #define ff first
- #define ss second
- #define all(v) v.begin(),v.end()
- #define rall(v) v.rbegin(),v.rend()
- #define read() freopen("input.txt", "r", stdin)
- #define write() freopen("output.txt", "w", stdout)
- /// Constants
- #define eps 1e-9
- #define PI acos(-1.0) // 3.1415926535897932
- #define MAX 1000009
- vector<string>num;
- int mx=0;
- void cal()
- {
- int carry=0,temp,mod,i=0,j;
- char digit;
- string sum;
- for(i=0;i<mx;i++){
- temp=carry;
- for(j=0;j<num.size();j++){
- if(i<num[j].size()){
- temp=temp+(num[j][i]-'0');
- }
- }
- mod=temp%10;
- sum.insert(sum.begin()+i,mod+'0');
- carry=temp/10;
- }
- if(!mx)
- sum.insert(sum.begin()+i,'0');
- while(carry){
- mod=carry%10;
- sum.insert(sum.begin()+i,mod+'0');
- i++;
- carry/=10;
- }
- reverse(sum.begin(),sum.end());
- cout<<sum<<endl;
- }
- int main()
- {
- read();
- write();
- string s;
- while(true){
- cin>>s;
- if(s.size()==1 && s[0]-'0'==0) break;
- int sz=s.size();
- if(sz>mx) mx=sz;
- reverse(s.begin(),s.end());
- num.push_back(s);
- }
- cal();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement