結果

問題 No.297 カードの数式
ユーザー RIGIHRIGIH
提出日時 2017-08-03 16:30:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,311 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 71,368 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 01:35:50
合計ジャッジ時間 1,524 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define LL long long
#define INF 100000000
using namespace std;
int keta(int n,int k){return (n/int(pow(10,double(k-1)))) % 10;} //nの下からk桁目


int main(){
	
	int n;
	cin>>n;
	char c[16];
	int cp=0,cm=0;
	int x[15];
	int j=0;
	int cz=0;
	rep(i,n){
		cin>>c[i];
		if(c[i]=='+') cp++;
		else if(c[i]=='-') cm++;
		else{
			x[j]=int(c[i])-48;
			j++;
		}
	}
	sort(x,x+j);
	rep(i,j){
		//cout<<x[i]<<endl;
		if(x[i]==0)cz++;
	}
	
	ll MAX=0;
	int i=0;
	//cout<<cz<<endl;
	while(i!=cm){
		MAX-=x[i+cz];
		i++;
	}
	while(i!=cm+cp){
		MAX+=x[i+cz];
		i++;
	}
	ll a=0;
	for(int k=j-1;k>=i+cz;k--){
		a*=10;
		a+=x[k];
	}
	a*=pow(10,double(cz));
	//cout<<a<<endl;
	MAX+=a;

	ll MIN=0;
	i=0;
	//cout<<cz<<endl;^
	cp++;cm--;
	while(i!=cp){
		MIN+=x[i+cz];
		i++;
	}
	while(i<cm+cp){
		//cout<<"W"<<endl;
		MIN-=x[i+cz];
		i++;
	}
	a=0;
	for(int k=j-1;k>=i+cz;k--){
		a*=10;
		a+=x[k];
	}
	a*=pow(10,double(cz));
	//cout<<a<<endl;
	MIN-=a;

	cout<<MAX<<" "<<MIN<<endl;

	return 0;
	
}
0