結果
| 問題 | 
                            No.193 筒の数式
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-08-31 20:55:37 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 1,000 ms | 
| コード長 | 884 bytes | 
| コンパイル時間 | 606 ms | 
| コンパイル使用メモリ | 111,592 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-12 04:02:47 | 
| 合計ジャッジ時間 | 1,276 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
ソースコード
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random;
import std.string, std.conv, std.stdio, std.typecons;
void main()
{
  auto s = readln.chomp;
  auto r = iota(s.length)
    .map!(i => s[i..$] ~ s[0..i])
    .filter!(s => s.front != '+' && s.front != '-' && s.back != '+' && s.back != '-')
    .map!(calc)
    .reduce!(max);
  writeln(r);
}
int calc(string s)
{
  auto acc = 0, buf = 0;
  char op;
  foreach (c; s) {
    if (c >= '0' && c <= '9') {
      buf = buf * 10 + (c - '0');
    } else if (c == '+' || c == '-') {
      applyOp(acc, buf, op);
      op = c;
    }
  }
  applyOp(acc, buf, op);
  return acc;
}
void applyOp(ref int acc, ref int buf, ref char op)
{
  if (op == '+') {
    acc = acc + buf;
  } else if (op == '-') {
    acc = acc - buf;
  } else {
    acc = buf;
  }
  buf = 0;
}