結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
maru
|
| 提出日時 | 2016-05-03 18:47:52 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 904 bytes |
| コンパイル時間 | 3,536 ms |
| コンパイル使用メモリ | 75,296 KB |
| 実行使用メモリ | 54,220 KB |
| 最終ジャッジ日時 | 2024-11-15 22:10:35 |
| 合計ジャッジ時間 | 8,990 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 10 |
ソースコード
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class yukicoder_222 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
String str = stdIn.next();
final String PLUS = "+";
Pattern p = Pattern.compile("^[-]?[0-9]{1,6}");
Matcher m = p.matcher(str);
if (m.find()) {
String matchstr =m.group();
int n1 = Integer.parseInt(matchstr);
int n2 = Integer.parseInt(str.substring(matchstr.length() + 1));
int result = 0;
if (str.substring(matchstr.length(),matchstr.length() + 1).equals(PLUS)) {
if (str.substring(matchstr.length() + 1,matchstr.length() + 2) == "-") {
result = n1 + Math.abs(n2);
} else {
result = n1 - n2;
}
} else {
result = n1 + n2;
}
System.out.println(result);
} else {
System.out.println("no matches!");
}
}
}
maru