Submission #01972
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include <bits/stdc++.h> #define PB push_back #define MP make_pair #define REP(i,n) for (int i=0;i<(n);i++) #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define ALL(a) (a).begin(),(a).end() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair< int , int > P; double EPS=1e-8; string add(string a,string b){ if (a.size()>b.size())swap(a,b); string res= "" ; bool ok= false ; int num=0; reverse(ALL(a)); reverse(ALL(b)); REP(i,a.size()){ num=(a[i]- '0' )+(b[i]- '0' ); if (ok)num++; if (num>=10)ok= true ; else ok= false ; res+=num%10+ '0' ; } if (ok){ if (a.size()==b.size())res+= '1' ; else { ok= true ; REP(i,b.size()-a.size()){ num=b[i+a.size()]- '0' ; if (ok)num++; if (num>=10){ ok= true ; } else { ok= false ; } res+=num%10+ '0' ; } if (ok){ res+= '1' ; } } } else { REP(i,b.size()-a.size()){ res+=b[a.size()+i]; } } reverse(ALL(res)); return res; } int main(){ string a,b,c,d; cin>>a>>b>>c>>d; cout<<add(a,add(b,add(c,d)))<<endl; } |
ステータス
項目 | データ |
---|---|
問題 | 0007 - みらくるくるる |
ユーザー名 | 西田武志 |
投稿日時 | 2015-12-03 18:16:49 |
言語 | C++11 |
状態 | Accepted |
得点 | 2 |
ソースコード長 | 1533 Byte |
最大実行時間 | 12 ms |
最大メモリ使用量 | 476 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 2 / 2 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
Alice_in1.txt | AC | 12 ms | 476 KB |
1
|