알고리즘

    백준 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 =..

    백준 11720번[문자열] 숫자의 합

    1) Scanner을 활용한 방법 import java.util.Scanner; public class Back_11720 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int testCase = sc.nextInt(); // 숫자의 합 변수 int sum = 0; // 2번째 입력을 String으로 받아준다. String str = sc.next(); // testCase 만큼 돌면서 sum 변수에 숫자형으로 저장. for (int i = 0; i < testCase; i++) { sum += str.charAt(i)-'0'; } System.out.println(sum); } } 2) BufferedRea..

    백준 11654번[문자열] 아스키코드

    1) Scanner를 이용한 풀이 import java.util.Scanner; public class Back_11654 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); String str = sc.next(); // 입력받은 문자열 int형으로 형변환. int code = str.charAt(0); // 형변환된 문자열 출력 System.out.println(code); } }