분류 전체보기

    백준 2098번[문자열] 상수

    1) Scanner을 이용한 풀이 ● StirngBuilder.append() 메소드를 이용해 입력받은 숫자를 넣어주고, reverse() 메소드를 이용해 뒤집어준다. ● 이후 문자로 바꿔주기 위해 toString() 메소드를 사용한다. import java.util.Scanner; public class Back_2908 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a = in.nextInt(); int b = in.nextInt(); StringBuilder Fsb = new StringBuilder(); StringBuilder Ssb = new StringBuilder(); in.close()..

    백준 1152번[문자열] 단어의 개수

    1) Scanner을 이용한 풀이 ● Buffered을 사용해서 알고리즘을 풀어봤기에 StringTokenizer을 사용해서 손쉽게 풀 수 있었다. import java.util.Scanner; import java.util.StringTokenizer; public class Back_1152 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); String str = sc.nextLine(); StringTokenizer st; int count = 0; st = new StringTokenizer(str, " "); while (st.hasMoreElements()) { // while의 무한 반복을 막기 위해..

    백준 1157번[문자열] 단어 공부

    1) Scanner을 이용한 풀이 import java.util.Scanner; public class Back_1157 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); String str = sc.next(); // 알파벳 만큼의 배열 생성 int[] arr = new int[26]; // 입력받은 문자를 탐색해 소문자인지 대문자인지 판별하기 위한 반복문 for (int i = 0; i < str.length(); i++) { // 소문자일 경우 if (str.charAt(i)

    백준 2675번[문자열] 문자열 반복

    1) Scanner을 이용한 풀이 import java.util.Scanner; public class Back_2675 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int testCase = sc.nextInt(); for (int i = 0; i < testCase; i++) { // 반복할 횟수 int r = sc.nextInt(); String str = sc.next(); // 입력받은 문자 길이만큼 탐색하는 반복문 for (int j = 0; j < str.length(); j++) { // 반복할 횟수만큼 한 문자 출력하기 for (int k = 0; k < r; k++) { System.out..

    백준 10809번[문자열] 알파벳 찾기

    1) Scanner 이용해서 풀이 ● 두번 째 for문에서 조건을 걸지 않는다면 오답으로 처리 된다. ● 예) baekjoon 입력 시 1 0 2 -1 -1 -1 -1 -1 -1 4 3 -1 -1 7 6 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 이 출력되는데 arr[14]에서 6이 나오는 이유는 문자 'o'가 2번 나와서 그런 것..(중복되는 문자) 주의하자. import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); String str = sc.next(); int[] arr = new int[26]; for (int i =..