結果
| 問題 |
No.193 筒の数式
|
| コンテスト | |
| ユーザー |
くれちー
|
| 提出日時 | 2017-02-04 19:23:42 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 1,198 bytes |
| コンパイル時間 | 299 ms |
| コンパイル使用メモリ | 22,400 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-24 06:17:44 |
| 合計ジャッジ時間 | 1,076 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:51:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
51 | scanf("%s", s);
| ^~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#define rep(i, n) for (i = 0; i < n; i++)
#define rrep(i, n) for (i = n; i >= 0; i--)
#define max(a, b) (a > b ? a : b)
#define inf 1145141919
#define minus 0
#define plus 1
bool is_operator(char c) {
if (c == '+' || c == '-') return true;
else return false;
}
bool is_calcable(char *s, int l) {
if (is_operator(s[0]) || is_operator(s[l - 1])) return false;
int i; rep(i, l - 1)
if (is_operator(s[i]) && is_operator(s[i + 1])) return false;
return true;
}
int calc(char *s, int l) {
int i, ti = 0, oi = 0, t[5] = {}, o[5] = {}, ans = 0;
rep(i, l) {
while (!is_operator(s[i]) && i < l) {
t[ti] *= 10;
t[ti] += s[i] - '0';
i++;
}
if (i < l) o[oi] = s[i] == '+' ? plus : minus;
ti++; oi++;
}
ans = t[0];
rep(i, oi) {
if (o[i] == plus) ans += t[i + 1];
else ans -= t[i + 1];
}
return ans;
}
void rotate(char *s, int l) {
char t = s[l - 1];
int i; rrep(i, l - 1) s[i + 1] = s[i];
s[0] = t;
return;
}
int main() {
char s[11];
scanf("%s", s);
int i, ans = -inf, l = strlen(s);
rep(i, l) {
if (is_calcable(s, l)) ans = max(ans, calc(s, l));
rotate(s, l);
}
printf("%d\n", ans);
return 0;
}
くれちー