結果

問題 No.297 カードの数式
ユーザー snteasntea
提出日時 2015-11-09 15:14:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,357 bytes
コンパイル時間 1,500 ms
コンパイル使用メモリ 150,704 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-11 15:26:04
合計ジャッジ時間 2,646 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <cmath>
#include <climits>
#include <cstdio>

using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define DEBUG(x) cout<<#x<<": "<<x<<endl

typedef pair<int,int> P;
typedef long long int LL;
typedef pair<LL,LL> LP;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	vector<char> c;
	cin >> N;
	int np = 0, nm = 0;
	vector<int> num;
	REP(i,N){
		char c;
		cin >> c;
		if(c == '+'){
			np++;
		}else if(c == '-'){
			nm++;
		}else{
			num.push_back(c-'0');
		}
	}
	int ans1 = 0, ans2 = 0;
	vector<int> num2;
	sort(ALL(num));
	//REP(i,SZ(num))	DEBUG(num[i]);
	int p = 0;
	REP(i,nm){
		num2.push_back(num[i]);
		p++; 
	}
	REP(i,np){
		num2.push_back(num[i]);
		p++;
	}
	int m = 0;
	RFOR(i,p,SZ(num)){
		m *= 10;
		m += num[i];
	}
	num2.push_back(m);
	p = 0;
	//REP(i,SZ(num2))	DEBUG(num2[i]);
	REP(i,nm){
		ans1 -= num2[p];
		//DEBUG(ans1);
		p++; 
	}
	REP(i,np){
		ans1 += num2[p];
		//DEBUG(ans1);
		p++;
	}
	//DEBUG(num[p]);
	ans1 += num2[p];
	p = 0;
	REP(i,np+1){
		ans2 += num2[p];
		p++;
	}
	REP(i,nm){
		ans2 -= num2[p];
		p++;
	}
	cout << ans1 << ' ' << ans2 << endl;
	return 0;
}
0