結果

問題 No.297 カードの数式
ユーザー naimonon77naimonon77
提出日時 2016-01-08 17:36:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,392 bytes
コンパイル時間 1,350 ms
コンパイル使用メモリ 162,556 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 16:49:20
合計ジャッジ時間 2,464 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:67:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   67 |         scanf(" %c",&c);
      |         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */
char num[18] = {0};
int N;
int num_top = 0;
ll s_max(int plus_cnt,int minus_cnt)
{
  char s_tmp[18];
  int tmp = N-2*plus_cnt-2*minus_cnt;
  strncpy(s_tmp,num,tmp);
  s_tmp[tmp] = 0;
  ll max = atoi(s_tmp);
  while(plus_cnt) {
	max += num[tmp++] - '0';
	plus_cnt--;
  }
  while(minus_cnt) {
	max -= num[tmp++] - '0';
	minus_cnt--;
  }
  return max;
}
ll s_min(int plus_cnt,int minus_cnt)
{
  char s_tmp[18];
  ll min;
  if(minus_cnt) {
	min = num[num_top-1] - '0';
	int tmp = N-2*plus_cnt-2*minus_cnt;
	minus_cnt--;
	strncpy(s_tmp,num,tmp);
	s_tmp[tmp] = 0;
	min -= atoi(s_tmp);
	
	while(minus_cnt) {
	  min -= num[tmp++] - '0';
	  minus_cnt--;
	}
	while(plus_cnt) {
	  min += num[tmp++] - '0';
	  plus_cnt--;
	}
  }
  else {
	return -1;
  }
  return min;
}
int main(void)
{
  int i,j,k;
  int plus_cnt = 0;
  int minus_cnt = 0;
  char c;
  
  cin >> N;
  for(i=0;i<N;i++) {
	scanf(" %c",&c);
	if(c == '+') plus_cnt++;
	else if(c == '-') minus_cnt++;
	else {
	  num[num_top] = c;
	  num_top++;
	}
  }
  sort(num,num+num_top,greater<int>());
  ll max = s_max(plus_cnt,minus_cnt);
  ll min = s_min(plus_cnt,minus_cnt);
  printf("%lld %lld\n",max,min);
  
  return 0;
}
0