結果

問題 No.3062 A + B
ユーザー pockynypockyny
提出日時 2020-04-01 22:01:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 873 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 78,136 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-09 18:16:00
合計ジャッジ時間 1,273 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int a,b; cin >> a >> b;
    bool flag1 = false,flag2 = false;
    if(a<0){
        flag1 = true; a *= -1;
    }
    if(b<0){
        flag2 = true; b *= -1;
    }
    int c = 0,d = 0;
    int dig = 0;
    while(a){
        c += a&1;
        dig++;
        a /= 2;
    }
    while(b){
        d += b&1;
        dig++;
        b /= 2;
    }
    if(flag1) c *= -1;
    if(flag2) d*= -1;
    int e = c + d;
    bool flag3 = false;
    if(e<0){
        flag3 =true; e *= -1;
    }
    if(e==0){
        cout << 0 << endl;
        return 0;
    }
    vector<int> v;
    while(e){
        v.push_back(e&1);
        e /= 2;
    }
    reverse(v.begin(),v.end());
    if(flag3){
        cout << "-";
    }
    for(int i=0;i<v.size();i++){
        cout << v[i];
    }
    cout << endl;
}

0