結果

問題 No.8062 A + B
コンテスト
ユーザー yuunegi
提出日時 2026-01-30 23:53:18
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 817 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,845 ms
コンパイル使用メモリ 337,084 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-30 23:53:24
合計ジャッジ時間 4,905 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
int main(void){
    string a,b;
    cin>>a>>b;
    string s=a+b;
    if(s=="-00"){
        cout<<0<<endl;
        return 0;
    }
    if(b[0]!='-'&&b[0]!='+'){
        int f3=0;
        for(int i=0;i<a.size();i++){
            if(a[i]!='0'&&a[i]!='+')f3++;
            if(f3)cout<<a[i];
        }
        cout<<b<<endl;
        return 0;
    }
    long long a1=0,ans=0;
    int f=0,f2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='-'){
            ans+=a1*(f==-1?-1:1);
            f=-1;
            a1=0;
            f2++;
        }else if(s[i]=='+'){
            ans+=a1*(f==-1?-1:1);
            a1=0;
            f=0;
        }else{
            a1*=10;
            a1+=s[i]-'0';
        }
    }
    ans+=a1*(f==-1?-1:1);
    cout <<ans<<endl;
    return 0;
}
0