๐Ÿ”ฅBaekjoon start๐Ÿ”ฅ

arielยท2021๋…„ 11์›” 24์ผ
0

Baekjoon

๋ชฉ๋ก ๋ณด๊ธฐ
14/14
post-thumbnail

2021-11-24

โœ์ช ์™€ ํ•จ๊ป˜ ํ•˜๋ฃจ์— 30๋ถ„ ์ด์ƒ ์‹œ์ž‘โœจ

2798

https://tooo1.tistory.com/28

import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
	
		int[]array = new int[N];
		
		for(int i = 0; i<N; i++) {
			array[i] = sc.nextInt();
		}
		
		int result = search(array, N, M);
		System.out.println(result);
	}
	
	static int search(int[] array, int N, int M) {
		int result=0;
		
		//์ฒซ๋ฒˆ์งธ ์นด๋“œ
		for(int i =0; i< N -2; i++) {
			
			if(array[i]>M) continue;
			//๋‘๋ฒˆ์งธ ์นด๋“œ
			for(int j = i+1; j< N - 1; j++) {
				if(array[i] + array[j] > M) continue;
				//์„ธ๋ฒˆ์งธ ์นด๋“œ
				for(int k = j+1; k<N; k++) {
					// ์„ธ์ˆ˜์˜ ํ•ฉ : temp
					int temp = array[i] + array[j] + array[k];
					//๋”œ๋Ÿฌ๊ฐ€ ๋ถ€๋ฅธ ์ˆซ์ž์™€ ์ผ์น˜ํ•˜๋ฉด temp return
					if(M == temp) {
						return temp;
					}
					if(result < temp && temp < M) {
						result = temp;
					}
				}
			}
		}
		
		return result;
	}
}

2231

import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int result = 0;
		
		for(int i = 0; i<N; i++) {
			int number = i;
			int sum = 0;//๊ฐ ์ž๋ฆฟ์ˆ˜ ํ•ฉ ๋ณ€์ˆ˜
			
			while(number !=0) {
				sum += number%10; //๊ฐ ์ž๋ฆฟ์ˆ˜ ๋”ํ•˜๊ธฐ
				number /= 10;
			}
			
			//i ๊ฐ’๊ณผ ๊ฐ ์ž๋ฆฟ์ˆ˜ ๋ˆ„์ ํ•ฉ์ด ๊ฐ™์„ ๊ฒฝ์šฐ(์ƒ์„ฑ์ž๋ฅผ ์ฐพ์•˜์„ ๊ฒฝ์šฐ)
			if(sum + i == N) {
				result = i;
				break;
			}
		}
		System.out.println(result);
	}
	
}

7568

import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[][] arr = new int[N][2];
		
		for(int i = 0; i<N; i++) {
			arr[i][0] = sc.nextInt(); //๋ชธ๋ฌด๊ฒŒ
			arr[i][1] = sc.nextInt(); //ํ‚ค
	
		}	
		for(int i=0; i<N; i++) {
			int rank = 1;
			
			for(int j=0;j<N; j++) {
				if(i == j) continue;//๊ฐ™์€ ์‚ฌ๋žŒ์€ ๋น„๊ตํ•  ํ•„์š”์—†๋‹ค
				if(arr[i][0] < arr[j][0] && arr[i][1] < arr[j][1]) {
					rank++;
				}
			}
			System.out.print(rank + " ");
		}	
	}
}

1018

import java.util.Scanner;
public class Main {
	
	public static boolean[][] arr;
	public static int min = 64;
	
	
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		arr = new boolean[N][M];
		
		for(int i= 0; i<N; i++) {
			String str = sc.next();
			
			for(int j =0; j<M; j++) {
				if(str.charAt(j)=='W') {
					arr[i][j] = true; //w์ผ๋•Œ๋Š” true
				}else {
					arr[i][j] = false;//B์ผ๋•Œ๋Š” false
				}
			}
		}
		
		int N_row = N -7;
		int M_col = M -7;
		
		for(int i=0; i< N_row; i++) {
			for(int j =0; j<M_col; j++) {
				find(i,j);
				
			}
		}
		System.out.println(min);
	}
	
	public static void find(int x, int y) {
		int end_x = x+8;
		int end_y = y+8;
		int count =0;
		
		boolean TF = arr[x][y];//์ฒซ ๋ฒˆ์งธ ์นธ์˜ ์ƒ‰
		
		for(int i =x; i<end_x; i++) {
			for(int j = y; j<end_y; j++) {
				
				//์˜ฌ๋ฐ”๋ฅธ ์ƒ‰์ด ์•„๋‹๊ฒฝ์šฐ count 1์ฆ๊ฐ€
				if(arr[i][j] != TF) {
					count++;
				}
				//๋‹ค์Œ ์นธ์€ ์ƒ‰์ด ๋ฐ”๋€Œ๋ฏ€๋กœ
				//๋ฐ˜๋Œ€๋กœ ๊ฐ’์„ ๋ณ€๊ฒฝํ•œ๋‹ค
				TF = (!TF);
			}
			TF = !TF;
		}
		
		count = Math.min(count, 64 - count);
	
	min = Math.min(min, count);
	}
}

1436

import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int num = 666;
		int count = 1;
		while(count !=N) {
			num++;
			
			//int ํ˜•์ธ num์„ string ์œผ๋กœ ๋ณ€ํ™˜ํ•œ ๋’ค, "666"์ด๋ž€ ๋ฌธ์ž์—ด์ด ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌ
			if(String.valueOf(num).contains("666")) {
				count++;
			}
		}
		System.out.println(num);
	}
}

[๊ธฐ๋ก]๐Ÿ“‘

.contains() : ๋Œ€์ƒ ๋ฌธ์ž์—ด์— ํŠน์ • ๋ฌธ์ž์—ด์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ํ•จ์ˆ˜์ด๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€