結果

問題 No.222 引き算と足し算
ユーザー めうめう🎒めうめう🎒
提出日時 2016-01-23 16:26:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 909 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 75,844 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 17:51:19
合計ジャッジ時間 1,673 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 1 ms
6,940 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:57:24: warning: ‘n’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |         else cout << n-m << endl;
      |                        ^
main.cpp:56:9: warning: ‘hugo’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |         if(hugo) cout << n+m << endl;
      |         ^~

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <math.h>
#include <stack>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <cstdio>
#include <vector>
using namespace std;

#define INF (1 << 30)
#define INFLL (1LL << 60)

int sstoi(string a){
	int n = 0;
	bool flag = 0;
	if(a[0] == '-'){
		flag = 1;
		a.erase(0,1);
	}else if(a[0] == '+'){
		a.erase(0,1);
	}

	for(int i = 0;i < a.size();i++){
		n = n*10;
		n += a[i] - '0';
	}
	if(flag) n = -n;
	return n;
}

int main() {
	bool hugo;
	string str;
	cin >> str;
	string a = "";
	int n,m;
	a += str[0];
	for(int i = 1;i < str.size();i++){
		if(str[i] >= '0' && str[i] <= '9') {
			a += str[i];
		}else{
			if(str[i] == '-') hugo = 1;
			else hugo = 0;
			n = sstoi(a);
			a = "";
			a += str[i+1];
			i++;
		}
	}
	m = sstoi(a);
	if(hugo) cout << n+m << endl;
	else cout << n-m << endl;
	return 0;
}
0