結果
問題 | No.297 カードの数式 |
ユーザー |
![]() |
提出日時 | 2015-11-07 00:37:47 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 1,000 ms |
コード長 | 1,039 bytes |
コンパイル時間 | 266 ms |
コンパイル使用メモリ | 22,784 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-26 02:23:25 |
合計ジャッジ時間 | 862 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:7:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 7 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf(" %c", &c[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <stdio.h>int n, v[12];char c[15];int main(void) {scanf("%d", &n);int i, j;for(i = 0; i < n; i++) {scanf(" %c", &c[i]);if('0' <= c[i] && c[i] <= '9') { v[ c[i] - '0' ]++; }else {if(c[i] == '+') { v[10]++; } else { v[11]++; }}}long long int large = 0;int counter = 0, d = n - 2 * (v[10] + v[11]);int max_p = 0, max_m = 0;int min_p = 0, min_m = 0;for(i = 9; 0 <= i; i--) {for(j = 0; j < v[i]; j++) {if(counter < d) {large = 10 * large + i;} else {if(counter < d + v[10] ) { max_p += i; } else { max_m += i; }if(counter < d + (v[11] - 1) ) { min_m += i; } else { min_p += i; }}counter++;}}long long int max = max_p - max_m + large;long long int min = min_p - min_m - large;if(v[11] == 0) {int sum = 0, base = 1;counter = 0;for(i = 9; 0 <= i; i--) {for(j = 0; j < v[i]; j++) {sum += i * base;counter++;if(counter % (v[10] + 1) == 0) { base *= 10; }}}min = sum;}printf("%lld %lld\n", max, min);return 0;}