結果
問題 | No.3021 Maximize eval |
ユーザー |
![]() |
提出日時 | 2025-02-15 17:41:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 860 bytes |
コンパイル時間 | 476 ms |
コンパイル使用メモリ | 41,276 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-02-15 17:41:05 |
合計ジャッジ時間 | 1,700 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:34:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | scanf("%d", &tn); | ~~~~~^~~~~~~~~~~ main.cpp:37:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 37 | scanf("%s", s); | ~~~~~^~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-** 3021.cc: No.3021 Maximize eval - yukicoder*/#include<cstdio>#include<cstring>#include<algorithm>using namespace std;/* constant */const int MAX_N = 500000;/* typedef *//* global variables */char s[MAX_N + 4];/* subroutines */inline bool isop(int i) { return s[i] == '+' || s[i] == '-'; }bool nbrop(int i, int n) {return ((i > 0 && isop(i - 1)) || (i + 1 < n && isop(i + 1)));}/* main */int main() {int tn;scanf("%d", &tn);while (tn--) {scanf("%s", s);int n = strlen(s);int sign = 1;for (int i = 0; i < n; i++) {if (s[i] == '?') {if (sign > 0) s[i] = '9';else if (i == n - 1 || nbrop(i, n)) s[i] = '1';else s[i] = '+', sign = 1;}else if (s[i] == '+') sign = 1;else if (s[i] == '-') sign = -1;}puts(s);}return 0;}