結果

問題 No.222 引き算と足し算
ユーザー 37zigen37zigen
提出日時 2020-02-19 11:29:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 1,000 ms
コード長 886 bytes
コンパイル時間 2,141 ms
コンパイル使用メモリ 78,088 KB
実行使用メモリ 41,320 KB
最終ジャッジ日時 2024-04-16 20:27:12
合計ジャッジ時間 7,456 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
41,176 KB
testcase_01 AC 111 ms
39,848 KB
testcase_02 AC 122 ms
41,080 KB
testcase_03 AC 124 ms
41,008 KB
testcase_04 AC 113 ms
39,884 KB
testcase_05 AC 124 ms
40,888 KB
testcase_06 AC 123 ms
41,072 KB
testcase_07 AC 122 ms
40,968 KB
testcase_08 AC 111 ms
39,912 KB
testcase_09 AC 125 ms
41,176 KB
testcase_10 AC 125 ms
41,012 KB
testcase_11 AC 113 ms
40,220 KB
testcase_12 AC 123 ms
41,144 KB
testcase_13 AC 126 ms
41,320 KB
testcase_14 AC 112 ms
40,076 KB
testcase_15 AC 124 ms
41,088 KB
testcase_16 AC 109 ms
40,224 KB
testcase_17 AC 124 ms
40,852 KB
testcase_18 AC 111 ms
40,192 KB
testcase_19 AC 126 ms
40,996 KB
testcase_20 AC 125 ms
41,096 KB
testcase_21 AC 123 ms
41,016 KB
testcase_22 AC 127 ms
41,128 KB
testcase_23 AC 114 ms
40,192 KB
testcase_24 AC 112 ms
40,076 KB
testcase_25 AC 125 ms
41,144 KB
testcase_26 AC 120 ms
41,048 KB
testcase_27 AC 114 ms
39,664 KB
testcase_28 AC 123 ms
41,180 KB
testcase_29 AC 113 ms
40,292 KB
testcase_30 AC 126 ms
41,128 KB
testcase_31 AC 126 ms
40,972 KB
testcase_32 AC 112 ms
40,360 KB
testcase_33 AC 123 ms
41,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		char[] cs=sc.next().toCharArray();
		int u=0,v=0;
		int su=1,sv=1;
		int p=0;
		if(cs[p]=='-') {
			++p;
			su*=-1;
		}else if(cs[p]=='+')++p;
		while((int)(cs[p]-'0')>=0&&9>=(int)(cs[p]-'0')) {
			u=10*u+(int)(cs[p]-'0');
			++p;
		}
		
		if(cs[p]=='+') {
			sv*=-1;
			++p;
		}else if(cs[p]=='-'){
			++p;
		}else {
			throw new AssertionError();
		}
		if(cs[p]=='-') {
			++p;
			sv*=-1;
		}else if(cs[p]=='+'){
			++p;
		}
		while(p<cs.length&&cs[p]-'0'>=0&&9>=cs[p]-'0') {
			v=10*v+(int)(cs[p]-'0');
			++p;
		}
		System.out.println(su*u+sv*v);
		
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}
0