본문 바로가기

[JAVA] 백준 1173 - 운동 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); // N분 int m = sc.nextInt(); // 초기 맥박 int M = sc.nextInt(); // 최대 맥박 int T = sc.nextInt(); // 1분당 T만큼 맥박 증가 int R = sc.nextInt(); // 1분당 R만큼 맥박 감소 int res = 0; // 결과 int move = 0; // 운동 한 시간 int init_m = m; // 초기 맥박 while(move != N) { res++; // 시간 증가 // 운동 후 ..
[JAVA] 백준 1159 - 농구 경기 import java.util.*; public class Main { public static void main(String[] args) { int[] alpha = new int[26]; ArrayList al = new ArrayList(); Scanner sc = new Scanner(System.in); int cnt = sc.nextInt(); for(int i=0; i= 5) { if(!al.contains((char)(index+97))) { al.add((char)(index+97)); } } } if(al.size() == 0) { // 같은 성을 가진 사람이 5명이 안될 경우 System.out.print("PREDAJA"); } else { // 같은 성을 가진 사람이 5명 이상일..
[JAVA] 백준 1152 - 단어의 개수 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); String[] parse = s.split(" "); int cnt = 0; for(int i=0; i 0) cnt++; } System.out.println(cnt); } }
[JAVA] 백준 1100 - 하얀 칸 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); boolean status = true; int count = 0; for(int i=0; i
[JAVA] 백준 1076 - 저항 코드 돌아가는데 엄청난 시간이 걸렸다 -_ㅠ public class Main { enum Color { black, brown, red, orange, yellow, green, blue, violet, grey, white; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int res = 0; for(int i=1; i
[JAVA] 백준 1075 - 나누기 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int F = sc.nextInt(); N = (N/100) * 100; // 마지막 두자리 00으로 바꾸기 while(N%F != 0) // 나누어 떨어지는 수 찾기 N++; N %= 100; if(N < 10) System.out.println("0" + N); else System.out.println(N); } }
[C++] 백준 10026 - 적록색약 백준 10026 - 적록색약 이 문제는 바보같은 나의 무지함으로 인해 메모리초과를 무려 5번이나 받은 문제이다. 아무리봐도, 로직이 맞는데 왜! 도대체 왜! 메모리 초과가 나는 것인가 계속 고민하다가 구글링을 했더니... [ BFS는 큐에서 뺀 다음이 아닌, 큐에서 넣을 때 방문 체크를 해줘야 한다]는 나만 모르던 사실을 알게되었다. 눈물을 훔치고 코드를 수정했다. 중복되는 코드를 줄일 수 있겠지만 내가 내 코드를 알아보기 힘들어서 그냥 두기로... :( 오늘도 성장하는...알린이로... #define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; // 상우하좌 방향 int dx[] = { -1, 0, 1, 0 }; int..
[C++] 백준 1012 - 유기농 배추 백준 1012 - 유기농 배추 백준의 단지번호 붙이기 문제랑 완전 똑같은 문제! :D 풀이 방법 1. 배추가 존재하는 좌표의 위치를 map 배열에 저장해둔다. 2. map 배열의 모든 좌표를 탐색하며, 배추가 심어진 좌표를 찾는다. 3. 배추가 심어진 좌표를 큐(q)에 넣어서 BFS 탐색한다. 4. BFS 탐색 시, 방문 표시는 배추 벌레에 번호를 매겨 visit 배열에 저장한다. #define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; // 4방향 상우하좌 int dx[] = { -1, 0, 1, 0 }; int dy[] = { 0, 1, 0, -1 }; int m, n, k; // 가로, 세로, 배추 개수 int m..