結果

問題 No.2323 Nafmo、A+Bをする
ユーザー p3loverp3lover
提出日時 2023-05-28 13:48:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 70,336 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 08:29:36
合計ジャッジ時間 1,558 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cmath>
#define rep(i,j,n) for(int i=j;i<n;i++)
using ll = long long; 
using namespace std;
//vector<int> DX={0,1,0,-1,0,1,-1,-1,1};
//vector<int> DY={0,0,1,0,-1,1,1,-1,-1};

int toten(const string& ans) {
    int nans = 0;
    int size = ans.size();

    for (int i = 0; i < size; ++i) {
        if (ans[i] == '1') {
            int plus = size - i - 1;
            nans += pow(2, plus);
        }
    }

    return nans;
}


int main(){
    string A,B; cin >> A >> B;
    string ans;

    bool upto=false;
    int N=A.size(),N2=B.size();
    while(N<N2){
        A='0' + A;
        N++;
    }
    while(N>N2){
        B='0' + B;
        N2++;
    }

    rep(i,0,N){
        if(!upto){
            int k=(A[i]-'0'+B[i]-'0')%2;
            if(k==0)continue;
            else {
                ans+=(k+'0');
                upto=true;
            }
        }
        else {
            int k=(A[i]-'0'+B[i]-'0')%2;
            ans+=(k+'0');
        }
    }


    cout << toten(ans) << endl;
}
0