結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
maru
|
| 提出日時 | 2016-05-03 19:14:42 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 124 ms / 1,000 ms |
| コード長 | 1,246 bytes |
| コンパイル時間 | 3,360 ms |
| コンパイル使用メモリ | 77,828 KB |
| 実行使用メモリ | 41,720 KB |
| 最終ジャッジ日時 | 2024-11-15 22:10:45 |
| 合計ジャッジ時間 | 8,478 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
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 = "+";
final String MINUS = "-";
Pattern p = Pattern.compile("^[-+]?[0-9]{1,6}");
Matcher m = p.matcher(str);
if (m.find()) {
String matchstr = m.group();
String matchstr1 = matchstr;
if(matchstr.substring(0, 1).equals(PLUS)) {
matchstr1 = matchstr.substring(1);
}
int n1 = Integer.parseInt(matchstr1);
int n2;
if (str.substring(matchstr.length() + 1,matchstr.length() + 2).equals(PLUS)) {
n2 = Integer.parseInt(str.substring(matchstr.length() + 2));
} else {
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).equals(MINUS)) {
result = n1 + Math.abs(n2);
} else {
result = n1 - n2;
}
} else {
result = n1 + n2;
}
System.out.println(result);
} else {
System.out.println("no matches!");
}
}
}
maru