[JAVA] 봉우리 - Array(1, 2차원 배열)
·
💡 Algorithm/인프런
public class INF0210 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] grid = new int[n+2][n+2]; //0 채우기 for (int i = 0; i grid[i][j-1] && grid[i][j] > grid[i][j+1]) { answer++; } } } return answer; } } 풀이 정석대로 가생이에 0 채우고 중앙에 값을 입력받아 상하좌우를 비교한 방식. 문제는 없지만 나중에 DFS, BFS 등 난이도 있는 문제를 하다 보면 영상처럼 경곗값 확인을 자주 하게 되는데, 나처럼 if문에 상하좌우 조건을 4개 걸 경우에..
[Java] 특정 문자 뒤집기 - String(문자열)
·
💡 Algorithm/인프런
Problem 💻영어 알파벳과 특수문자로 구성된 문자열이 주어지면 영어 알파벳만 뒤집고,특수문자는 자기 자리에 그대로 있는 문자열을 만들어 출력하는 프로그램을 작성하세요. Solution 💡public class INF0105 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); INF0105 inf = new INF0105(); System.out.println(inf.solution(s)); } public String solution(String s) { String answer = ""; ..
[JAVA] 단어 뒤집기 - String(문자열)
·
💡 Algorithm/인프런
public class INF0104T2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String[] arr = new String[n]; for (int i = 0; i < n; i++) { arr[i] = sc.next(); } INF0104T2 inf = new INF0104T2(); for(String s : inf.solution(n, arr)) { System.out.println(s); } } public ArrayList solution(int n, String[] arr) { ArrayList answer = new ArrayList(); //직접 뒤집..
[JAVA] 백준 #10250 - ACM 호텔
·
💡 Algorithm/백준
10250번: ACM 호텔 프로그램은 표준 입력에서 입력 데이터를 받는다. 프로그램의 입력은 T 개의 테스트 데이터로 이루어져 있는데 T 는 입력의 맨 첫 줄에 주어진다. 각 테스트 데이터는 한 행으로서 H, W, N, 세 정수 www.acmicpc.net public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int testCnt = sc.nextInt(); for (int i = 0; i < testCnt; i++) { int floor = sc.nextInt(); // 층수 입력 int room = sc.nextInt(); // 방 수 입력 int customer = sc.next..
[JAVA] 백준 #1157 - 단어 공부
·
💡 Algorithm/백준
1157번: 단어 공부 알파벳 대소문자로 된 단어가 주어지면, 이 단어에서 가장 많이 사용된 알파벳이 무엇인지 알아내는 프로그램을 작성하시오. 단, 대문자와 소문자를 구분하지 않는다. www.acmicpc.net public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.nextLine().toUpperCase(); int[] strCount = new int[26]; //알파벳 개수를 저장할 배열 for(int i=0; i
[JAVA] 백준 #2920 - 음계
·
💡 Algorithm/백준
2920번: 음계 다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다. 1부터 8까지 차례대로 연주한다면 ascending, 8 www.acmicpc.net public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] melody = new int[8]; for (int i=0; i melody[i - 1]){ isDecending = false; } } if (isAscending) { System.out.println("ascending"); } e..