結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-26 18:50:55 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,596 bytes |
| コンパイル時間 | 12,466 ms |
| コンパイル使用メモリ | 402,032 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-17 17:56:25 |
| 合計ジャッジ時間 | 13,920 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 17 |
ソースコード
use std::io::*;
fn main() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.trim().split_whitespace();
let s: Vec<char> = itr.next().unwrap().chars().collect();
let mut ops = Vec::new();
let mut num = Vec::new();
let mut now = 0;
let mut ok = false;
let mut head = false;
let n = s.len();
for i in 0..n {
if s[i] == '+' || s[i] == '-' {
ops.push(s[i]);
if i == 0 {
head = true;
}
if ok {
num.push(now);
now = 0;
ok = false;
}
} else {
ok = true;
now = now * 10 + (s[i] as u8 - '0' as u8) as i64;
}
}
num.push(now);
let mut ans = 0;
match ops.len() {
1 => {
ans = if ops[0] == '+' {
num[0] - num[1]
} else {
num[0] + num[1]
}
}
2 => {
ans = if head {
if ops[1] == '+' {
-num[0] - num[1]
} else {
-num[0] + num[1]
}
} else {
if ops[0] == '+' {
num[0] + num[1]
} else {
num[0] - num[1]
}
}
}
3 => {
ans = if ops[1] == '+' {
-num[0] + num[1]
} else {
-num[0] - num[1]
}
}
_ => {}
}
println!("{}", ans);
}