結果

問題 No.297 カードの数式
ユーザー mdj982mdj982
提出日時 2015-12-31 18:50:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,457 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 95,112 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 22:50:40
合計ジャッジ時間 1,640 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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() {
	lint N;
	cin >> N;
	lint countplus = 0, countminus = 0;
	vector<lint> list;
	Loop(i, N) {
		char buff;
		cin >> buff;
		if (buff == '+') countplus++;
		else if (buff == '-') countminus++;
		else {
			list.push_back((lint)(buff - '0'));
		}
	}
	lint ret1 = 0, ret2 = 0;
	sort(list.begin(), list.end(), greater<lint>());
	lint a = list.size() - countplus - countminus;
	Loop(i, a) ret1 += list[i] * (lint)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] * (lint)pow(10, a - 1 - i);
		Loop(i, countminus - 1) {
			ret2 -= list[a + i];
		}
		Loop(i, countplus+1) {
			ret2 += list[a + countminus - 1 + i];
		}
	}
	else {
		lint b = countplus + 1;
		lint 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