• Home
  • About
    • Ryureka Moment photo

      Ryureka

      Sin Prisa, Sin Pausa

    • About Me
    • Facebook
    • Github
    • Youtube
  • Projects
  • Posts
    • Posts
    • ProblemSolvings
    • Tags
    • Blog
    • Examples
  • ProblemSolving
    • ProblemSolving
    • BOJ
    • Programmers
    • SWEA
    • LeetCode
  • FrontEnd
    • FrontEnd
    • HTML
  • BackEnd
    • BackEnd
    • Server
      • Server
      • Spring
      • NodeJS
    • DataBase
      • DataBase
      • MySQL
      • MongoDB
  • Programming
    • Programming
    • Java
    • JS
    • Python
    • CleanCode
  • ComputerScience
    • DataStructure
    • Algorithm

[BOJ] 2621. 카드게임

15 Apr 2026

Reading time ~3 minutes

  • 풀이

풀이

import java.util.Scanner;

public class Main {
	static Scanner sc=new Scanner(System.in);
	static boolean arr[][]=new boolean [4][10];
	public static void main(String[] args) {
		for (int i = 0; i < 5; i++) {
			int color=colorToInt(sc.next().charAt(0));
			arr[color][sc.nextInt()]=true;
		}

		int ans=0;
		int one=One();
		int two=Two();
		int thr=Thr();
		int four=Four();
		int five=Five();
		int six=Six();
		int seven=Seven();
		int eight=Eight();
		int nine=Nine();
		
		if(one!=0) ans=one;
		if(two!=0) {
			if(two>ans) ans=two;
		}
		if(thr!=0) {
			if(thr>ans) ans=thr;
		}
		if(four!=0) {
			if(four>ans) ans=four;
		}
		if(five!=0){
			if(five>ans) ans=five;
		}
		if(six!=0) {
			if(six>ans) ans=six;
		}
		if(seven!=0) {
			if(seven>ans) ans=seven;
		}
		if(eight!=0) {
			if(eight>ans) ans=eight;
		}
		if(nine!=0) {
			if(nine>ans) ans=nine;
		}
		System.out.println(ans);
	}
	
	public static int One() {
		for (int i = 0; i < arr.length; i++) {
			for (int j = 1; j < arr[0].length-4; j++) {
				int cnt=0;
				for (int k = 0; k < 5; k++) {
					if(arr[i][j+k]) cnt++;
				}
				if(cnt==5) return j+4+900;
			}
		}
		return 0;
	}
	
	public static int Two() {
		for (int i = 1; i < arr[0].length; i++) {
			int cnt=0;
			for (int j = 0; j < arr.length; j++) {
				if(arr[j][i]) cnt++;
				if(cnt==4) return i+800;
			}
		}
		return 0;
	}
	
	public static int Thr() {
		int thr=0;
		int two=0;
		for (int i = 1; i < arr[0].length; i++) {
			int cnt=0;
			int tmp=0;
			for (int j = 0; j < arr.length; j++) {
				if(arr[j][i]) {
					cnt++;
					tmp=i;
				}
			}
			if(cnt==3) {
				thr=tmp;
			}
			if(cnt==2) {
				two=tmp;
			}
		}
		
		if(thr!=0 && two!=0) return thr*10+two+700;
		return 0;
	}
	
	public static int Four() {
		for (int i = 0; i < arr.length; i++) {
			int cnt=0;
			int max=0;
			for (int j = 1; j < arr[0].length; j++) {
				if(arr[i][j]) {
					max=j;
					cnt++;
				}
			}
			if(cnt==5) return max+600;
		}
		return 0;
	}
	
	public static int Five() {
		boolean check[]=new boolean [10];
		for (int i = 0; i < arr.length; i++) {
			for (int j = 1; j < arr[0].length; j++) {
				if(arr[i][j]) check[j]=true;
			}
		}

		for (int i = 1; i < check.length-4; i++) {
			int cnt=0;
			for (int j = 0; j < 5; j++) {
				if(check[i+j]) {
					cnt++;
				}
			}
			if(cnt==5) return i+4+500;
		}
		return 0;
	}
	
	public static int Six() {
		for (int i = 0; i < arr[0].length; i++) {
			int cnt=0;
			for (int j = 0; j < arr.length; j++) {
				if(arr[j][i]) cnt++;
				if(cnt==3) return i+400;
			}
		}
		return 0;
	}
	
	public static int Seven() {
		int two1=0;
		int two2=0;
		boolean flag=false;
		for (int i = 1; i < arr[0].length; i++) {
			int cnt=0;
			int tmp=0;
			for (int j = 0; j < arr.length; j++) {
				if(arr[j][i]) {
					cnt++;
					tmp=i;
				}
			}
			if(cnt==2) {
				if(!flag) {
					two1=tmp;
					flag=true;
				}else {
					two2=tmp;
				}
			}
		}
		
		if(two2>two1) {
			int tmp=two1;
			two1=two2;
			two2=tmp;
		}
		if(two1!=0 && two2!=0) return two1*10+two2+300;
		return 0;
	}
	
	public static int Eight() {
		for (int i = 1; i < arr[0].length; i++) {
			int cnt=0;
			for (int j = 0; j < arr.length; j++) {
				if(arr[j][i]) cnt++;
				if(cnt==2) return i+200;
			}
		}
		return 0;
	}
	
	public static int Nine() {
		int max=0;
		for (int i = 0; i < arr.length; i++) {
			for (int j = 1; j < arr[0].length; j++) {
				if(arr[i][j]) {
					if(j>max) {
						max=j;
					}
				}
			}
		}
		return max+100;
	}
	
	public static int colorToInt(char ch) {
		if(ch=='R') return 0;
		if(ch=='B') return 1;
		if(ch=='Y') return 2;
		if(ch=='G') return 3;
		return -1;
	}
}


구현많은 조건 분기 Share