結果

問題 No.297 カードの数式
ユーザー dgd1724dgd1724
提出日時 2016-10-23 07:21:35
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,429 bytes
コンパイル時間 2,183 ms
コンパイル使用メモリ 165,504 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-02 22:40:50
合計ジャッジ時間 2,371 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 RE -
testcase_05 AC 1 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 RE -
testcase_19 WA -
testcase_20 WA -
testcase_21 RE -
testcase_22 AC 1 ms
6,940 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

//const static double	de_PI	= 3.14159265358979323846;
//const static int	de_MOD	= 1000000007;
//const static int	de_MAX	= 999999999;
//const static int	de_MIN = -999999999;

int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());

	int N = 0;
	std::cin >> N;
	std::string num;
	int plus = 0, minus = 0;

	std::string temp;
	for (int i = 0; i < N; i++) {
		std::cin >> temp;
		switch (temp[0]) {
		case '+':plus++; break;
		case '-':minus++; break;
		default:num.push_back(temp[0]);
		}
	}

	std::sort(num.rbegin(), num.rend());

	int digit = num.length() - plus - minus;
	int max = std::stoi(num.substr(0, digit));

	for (int i = 0; i < plus; i++) {
		max += std::stoi(num.substr(digit, 1));
		digit++;
	}
	for (int i = 0; i < minus; i++) {
		max -= std::stoi(num.substr(digit, 1));
		digit++;
	}

	int min = 0;
	if (minus == 0) {
		std::sort(num.rbegin(), num.rend());
		digit = num.length() - plus;
		min = std::stoi(num.substr(0, digit));
		for (int i = 0; i < plus; i++) {
			min += std::stoi(num.substr(digit, 1));
			digit++;
		}
	}
	else {
		digit = num.length() - plus - minus;
		min = std::stoi(num.substr(0, digit))*-1;
		for (int i = 0; i < minus - 1; i++) {
			min -= std::stoi(num.substr(digit, 1));
			digit++;
		}
		for (int i = 0; i < plus + 1; i++) {
			min += std::stoi(num.substr(digit, 1));
			digit++;
		}
	}

	std::cout << max <<" " << min << std::endl;
	
}

0