結果

問題 No.222 引き算と足し算
ユーザー 37zigen37zigen
提出日時 2020-02-19 11:30:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 1,000 ms
コード長 861 bytes
コンパイル時間 2,272 ms
コンパイル使用メモリ 77,340 KB
実行使用メモリ 41,588 KB
最終ジャッジ日時 2024-04-16 20:28:08
合計ジャッジ時間 7,866 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
41,132 KB
testcase_01 AC 129 ms
41,304 KB
testcase_02 AC 129 ms
41,336 KB
testcase_03 AC 131 ms
41,312 KB
testcase_04 AC 131 ms
41,588 KB
testcase_05 AC 131 ms
41,272 KB
testcase_06 AC 132 ms
41,312 KB
testcase_07 AC 129 ms
41,076 KB
testcase_08 AC 128 ms
41,244 KB
testcase_09 AC 129 ms
41,228 KB
testcase_10 AC 133 ms
41,380 KB
testcase_11 AC 130 ms
41,216 KB
testcase_12 AC 131 ms
41,172 KB
testcase_13 AC 131 ms
41,524 KB
testcase_14 AC 128 ms
41,044 KB
testcase_15 AC 132 ms
41,276 KB
testcase_16 AC 134 ms
41,260 KB
testcase_17 AC 133 ms
41,144 KB
testcase_18 AC 137 ms
41,568 KB
testcase_19 AC 132 ms
41,048 KB
testcase_20 AC 131 ms
41,108 KB
testcase_21 AC 130 ms
41,160 KB
testcase_22 AC 133 ms
41,160 KB
testcase_23 AC 133 ms
41,400 KB
testcase_24 AC 135 ms
41,028 KB
testcase_25 AC 135 ms
41,048 KB
testcase_26 AC 133 ms
41,168 KB
testcase_27 AC 133 ms
41,216 KB
testcase_28 AC 131 ms
41,192 KB
testcase_29 AC 133 ms
41,432 KB
testcase_30 AC 135 ms
41,388 KB
testcase_31 AC 132 ms
41,380 KB
testcase_32 AC 132 ms
41,096 KB
testcase_33 AC 130 ms
41,364 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;
		}
		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