結果

問題 No.161 制限ジャンケン
ユーザー jp_stejp_ste
提出日時 2015-03-16 08:32:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 167 ms / 5,000 ms
コード長 971 bytes
コンパイル時間 2,224 ms
コンパイル使用メモリ 79,660 KB
実行使用メモリ 55,188 KB
最終ジャッジ日時 2024-05-07 11:57:29
合計ジャッジ時間 5,945 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
55,040 KB
testcase_01 AC 128 ms
54,188 KB
testcase_02 AC 155 ms
54,928 KB
testcase_03 AC 158 ms
54,952 KB
testcase_04 AC 155 ms
54,844 KB
testcase_05 AC 113 ms
53,052 KB
testcase_06 AC 159 ms
54,364 KB
testcase_07 AC 167 ms
54,716 KB
testcase_08 AC 160 ms
55,000 KB
testcase_09 AC 155 ms
55,040 KB
testcase_10 AC 153 ms
54,740 KB
testcase_11 AC 163 ms
55,076 KB
testcase_12 AC 156 ms
55,188 KB
testcase_13 AC 156 ms
55,012 KB
testcase_14 AC 155 ms
54,976 KB
testcase_15 AC 155 ms
54,976 KB
testcase_16 AC 157 ms
55,112 KB
testcase_17 AC 152 ms
54,860 KB
testcase_18 AC 152 ms
55,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int G = sc.nextInt();
		int C = sc.nextInt();
		int P = sc.nextInt();
		String S = sc.next();
		
		int ans = 0;
		String nextS = "";
		
		//勝てる手
		for(int i=0; i<S.length(); i++) {
			
			char look = S.charAt(i);
			boolean find = false;
			
			if(look == 'G') {
				if(P>0) { P--; ans+=3; find=true; }
				
			} else if(look == 'C') {
				if(G>0) { G--; ans+=3; find=true; }
				
			} else if(look == 'P') {
				if(C>0) { C--; ans+=3; find=true; }
			}
		
			if(find==false) {
				nextS += look;
			}
		}
		
		S = nextS;
		
		//あいこの手
		for(int i=0; i<S.length(); i++) {
			
			char look = S.charAt(i);
			
			if(look == 'G') {
				if(G>0) { G--; ans+=1; }
				
			} else if(look == 'C') {
				if(C>0) { C--; ans+=1; }
				
			} else if(look == 'P') {
				if(P>0) { P--; ans+=1; }
			}	
		}
		System.out.println(ans);
	}
}
0