結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
h_noson
|
| 提出日時 | 2016-02-17 13:13:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,180 bytes |
| コンパイル時間 | 697 ms |
| コンパイル使用メモリ | 68,140 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-22 07:27:28 |
| 合計ジャッジ時間 | 1,915 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 5 RE * 4 |
ソースコード
#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;
}
h_noson