paiza official website A place where you write a program and rank it and evaluate it You can appeal your programming ability to the companies you are looking for (I don't think it's practical, but if you solve it properly, you can see that it has the minimum ability.)
Problem: How to play rock-paper-scissors ・ Total number of games N ・ Total index M ・ Opponent's hand row S 3 are given as inputs, and the problem of determining the maximum number of wins against the opponent's hand when the total number of games and the total index are used exactly For details, link to
import java.util.ArrayList;
import java.util.Scanner;
/**
 *How to put out the hands of rock-paper-scissors(equivalent to paiza rank A)
 */
public class AS001{
	public static void main(String[] args) {
		//input
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		char[] handArray = sc.next().toCharArray();
		//Opponent hand analysis
		int[] handCount = new int[3]; //{G, C, P}
		for(char hand : handArray) {
			switch(hand) {
			case 'G':
				handCount[0]++;
				break;
			case 'C':
				handCount[1]++;
				break;
			case 'P':
				handCount[2]++;
				break;
			}//switch
		}//for
		//Hand pattern enumeration
		ArrayList<Integer[]> patternList = new ArrayList<>(100);
		for(int i = 0; i <= n; i++) {
			for(int j = 0; j <= n; j++) {
				int yubi = i * 2 + j * 5; //index
				int remain = n - i - j; //Number of remaining games
				if(yubi == m && remain >= 0) {
					//A combination that uses up your fingers within the total number of games
					Integer[] pattern = {remain, i, j}; //{g, c, p}
					patternList.add(pattern);
				}else if(yubi > m || remain < 0) {
					//If the number of games is used up or the index is exceeded, the next loop
					break;
				}//if
			}//for
		}//for
		//Calculate the pattern of maximum wins
		int maxWin = 0;
		for(Integer[] pattern : patternList) {
			int win = 0;
			win += Math.min(handCount[0], pattern[2]); //The other party is goo, I am par
			win += Math.min(handCount[2], pattern[1]); //The other party is par, I am choki
			win += Math.min(handCount[1], pattern[0]); //The other party is Choki, I am Goo
			if(win > maxWin) maxWin = win;
		}//for
		//output
		System.out.println(maxWin);
	}//main
}//class
All execution time is within 0.10 seconds
![]()  | 
|---|
Recommended Posts