結果

問題 No.297 カードの数式
ユーザー h_nosonh_noson
提出日時 2016-02-17 13:13:40
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,180 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 68,620 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 06:11:50
合計ジャッジ時間 2,096 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (int i = e-1; i >= s; i--)
#define rrep(i,n) RREP(i,0,n)
#define REP(i,s,e) for (int i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)

long long calc(string s) {
    if (s.empty())
        return 0;
    size_t len;
    long long x = stoi(s,&len);
    return x + calc(s.substr(len));
}

int main() {
    int n;
    cin >> n;
    string op;
    string num;
    rep(i,n) {
        char c;
        cin >> c;
        if (isdigit(c))
            num.push_back(c);
        else
            op.push_back(c);
    }
    sort(op.begin(),op.end());
    sort(num.begin(),num.end(),greater<char>{});
    int pos = num.size() - op.size();
    string ans = num.substr(0,pos);
    for (auto p = op.begin(), q = num.begin() + pos; p != op.end(); p++, q++) {
        ans.push_back(*p);
        ans.push_back(*q);
    }
    cout << calc(ans) << " ";
    ans = "";
    auto p = op.begin();
    auto q = num.rbegin();
    for (; p != op.end(); p++, q++) {
        ans.push_back(*q);
        ans.push_back(*p);
    }
    ans.append(num.substr(0,pos));
    cout << calc(ans) << endl;
    return 0;
}

0