結果

問題 No.161 制限ジャンケン
ユーザー Daigo HIROOKA
提出日時 2018-05-22 01:53:03
言語 Java
(openjdk 23)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 985 bytes
コンパイル時間 3,972 ms
コンパイル使用メモリ 77,984 KB
実行使用メモリ 41,568 KB
最終ジャッジ日時 2024-06-28 15:41:25
合計ジャッジ時間 6,492 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No161{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int num_G = sc.nextInt();
		int num_C = sc.nextInt();
		int num_P = sc.nextInt();
		String[] S = sc.next().split("");
		int num_G_you = 0;
		int num_C_you = 0;
		int num_P_you = 0;
		for(int i = 0; i < S.length; i++){
			if(S[i].equals("G")) num_G_you++;
			else if(S[i].equals("C")) num_C_you++;
			else num_P_you++;
		}

		int score = 0;

		// win game
		int num_G_C = Math.min(num_G, num_C_you);
		score += 3*num_G_C;
		num_G -= num_G_C;
		num_C_you -= num_G_C;

		int num_C_P = Math.min(num_C, num_P_you);
		score += 3*num_C_P;
		num_C -= num_C_P;
		num_P_you -= num_C_P;

		int num_P_G = Math.min(num_P, num_G_you);
		score += 3*num_P_G;
		num_P -= num_P_G;
		num_G_you -= num_P_G;

		// Draw game
		score += Math.min(num_G, num_G_you);
		score += Math.min(num_C, num_C_you);
		score += Math.min(num_P, num_P_you);

		System.out.println(score);
	}
}
0