結果

問題 No.222 引き算と足し算
ユーザー ぴろず
提出日時 2015-06-05 22:32:28
言語 Java
(openjdk 23)
結果
AC  
実行時間 134 ms / 1,000 ms
コード長 668 bytes
コンパイル時間 2,326 ms
コンパイル使用メモリ 79,252 KB
実行使用メモリ 41,652 KB
最終ジャッジ日時 2024-11-15 21:22:21
合計ジャッジ時間 7,294 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

package no222;

import java.util.Scanner;

public class Main {

	static char[] s;
	static int ind = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		s = sc.next().toCharArray();
		int a = number();
		char op = s[ind++];
		int b = number();
		if (op == '+') {
			System.out.println(a-b);
		}else{
			System.out.println(a+b);
		}
	}

	public static int number() {
		boolean negative = false;
		if (s[ind] == '+') {
			ind++;
		}else if(s[ind] == '-') {
			ind++;
			negative = true;
		}
		int n = 0;
		while(ind < s.length && Character.isDigit(s[ind])) {
			n = n * 10 + s[ind] - '0';
			ind++;
		}
		return negative ? -n : n;
	}

}
0