結果

問題 No.297 カードの数式
ユーザー mdj982mdj982
提出日時 2015-12-31 18:47:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,446 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 97,516 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 12:52:57
合計ジャッジ時間 1,971 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
//#include "toollib.h"
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#pragma warning (disable:4018)

using namespace std;
typedef long long int lint;

typedef struct {
	int x;
	int y;
}coordinate;

//***** Main Program *****

int main() {
	int N;
	cin >> N;
	int countplus = 0, countminus = 0;
	vector<int> list;
	Loop(i, N) {
		char buff;
		cin >> buff;
		if (buff == '+') countplus++;
		else if (buff == '-') countminus++;
		else {
			list.push_back((int)(buff - '0'));
		}
	}
	int ret1 = 0, ret2 = 0;
	sort(list.begin(), list.end(), greater<int>());
	int a = list.size() - countplus - countminus;
	Loop(i, a) ret1 += list[i] * (int)pow(10, a - 1 - i);
	Loop(i, countplus) {
		ret1 += list[a + i];
	}
	Loop(i, countminus) {
		ret1 -= list[a + countplus + i];
	}
	cout << ret1 << " ";
	if (countminus != 0) {
		Loop(i, a) ret2 -= list[i] * (int)pow(10, a - 1 - i);
		Loop(i, countminus - 1) {
			ret2 -= list[a + i];
		}
		Loop(i, countplus+1) {
			ret2 += list[a + countminus - 1 + i];
		}
	}
	else {
		int b = countplus + 1;
		int p = 0, q = 1;
		Loop(i, list.size()) {
			if (p == b) {
				p = 0;
				q *= 10;
			}
			ret2 += list[i] * q;
			p++;
		}
	}
	cout << ret2 << endl;
	return 0;
}
0