結果

問題 No.297 カードの数式
ユーザー HankHank
提出日時 2016-06-08 12:39:00
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,749 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 23,936 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 09:42:30
合計ジャッジ時間 1,055 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 0 ms
5,376 KB
testcase_08 AC 0 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 0 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 0 ms
5,376 KB
testcase_13 AC 0 ms
5,376 KB
testcase_14 AC 0 ms
5,376 KB
testcase_15 AC 0 ms
5,376 KB
testcase_16 AC 0 ms
5,376 KB
testcase_17 AC 0 ms
5,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:12:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |   scanf("%d\n",&N);
      |   ^~~~~~~~~~~~~~~~
main.c:14:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |     scanf("%s",&c[i]);
      |     ^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
int main(){
  int N,i,j;
  int num[10]={0},num2[10]={0},p=0,m=0;
  char c[15];
  int num_count,sign_count;
  int big[14]={0},big_num=0;
  int little[14]={0},little_num=0;
  int min=0,max=0;
  
  scanf("%d\n",&N);
  for(i=0;i<N;i++){
    scanf("%s",&c[i]);
  }

  for(i=0;i<N;i++){
    switch(c[i]){
    case '+':p++;break;
    case '-':m++;break;
    case '0':num[0]++;break;
    case '1':num[1]++;break;
    case '2':num[2]++;break;
    case '3':num[3]++;break;
    case '4':num[4]++;break;
    case '5':num[5]++;break;
    case '6':num[6]++;break;
    case '7':num[7]++;break;
    case '8':num[8]++;break;
    case '9':num[9]++;break;
    }
  }
  sign_count = p+m;
  num_count = N-sign_count;
  for(i=0;i<10;i++){
    num2[i]=num[i];
  }
  for(i=0;i<sign_count;i++){
    for(j=0;j<10;j++){
      if(num[j]!=0){
	big[big_num]=j;
	num[j]--;
	big_num++;
	break;
      }
    }
  }
  for(i=0;i<num_count-sign_count;i++){
    for(j=9;j>=0;j--){
      if(num[j]!=0){
	big[big_num]=big[big_num]*10+j;
	num[j]--;
	break;
      }	
    }
  } 
  
  for(i=0;i<sign_count;i++){
    for(j=9;j>=0;j--){
      if(num2[j]!=0){
	little[little_num]=j;
	num2[j]--;
	little_num++;
	break;
      }
    }
  }
    for(i=0;i<num_count-sign_count;i++){
      for(j=0;j<10;j++){
	if(num2[j]!=0){
	  little[little_num]=little[little_num]*10+j;
	  num2[j]--;
	  break;
	}	
      }
    }
    
  max = big[big_num];
  for(i=1;i<=p;i++){
    max+=big[big_num-i];
  }
  for(i=1;i<=m;i++){
    max -= big[i-1];
  }
  if(m>0){
    for(i=0;i<=p;i++){
      min += big[i]; 
    }
    for(j=0;j<m;j++){
      min -= big[i+j];
    }
  }
  else{
    for(i = 0;i<=p;i++){
      min += little[i];
    }
  }

  printf("%d %d\n",max,min);
  return 0;
}
0