結果

問題 No.297 カードの数式
ユーザー ldsybldsyb
提出日時 2016-03-11 20:49:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,004 bytes
コンパイル時間 754 ms
コンパイル使用メモリ 69,940 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 05:29:18
合計ジャッジ時間 1,887 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
   int add = 0,sub = 0,n;
   vector<int> v;
   cin >> n;
   for(int i = n;i--;){
      char c;
      cin >> c;
      if(c == '+'){
         add++;
         continue;
      }else if(c == '-'){
         sub++;
         continue;
      }
      v.push_back(c - '0');
   }
   stable_sort(v.begin(),v.end());
   int i,max = 0,min = 0,tmp = 0;
   //----------maxを求める処理----------//
   for(i = v.size() - 1;i >= add + sub;i--){
      max *= 10;
      max += v[i];
   }
   for(;i >= sub;i--) max += v[i];
   for(;i >= 0;i--) max -= v[i];
   //------maxを求める処理ここまで------//
   //----------minを求める処理----------//
   min = v[0];
   for(i = v.size() - 1;i >= add + sub;i--){
      tmp *= 10;
      tmp += v[i];
   }
   min -= tmp;
   tmp = 0;
   for(;i >= 1;i--) tmp += v[i];
   min += tmp;
   //------minを求める処理ここまで------//
   cout << max << ' ' << min << endl;
}
0