2908번: 상수
상근이의 동생 상수는 수학을 정말 못한다. 상수는 숫자를 읽는데 문제가 있다. 이렇게 수학을 못하는 상수를 위해서 상근이는 수의 크기를 비교하는 문제를 내주었다. 상근이는 세 자리 수 두
www.acmicpc.net
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
StringBuffer sb = new StringBuffer(str);
str = sb.reverse().toString();
String str2 = sc.next();
StringBuffer sb2 = new StringBuffer(str2);
str2 = sb2.reverse().toString();
int n1 = Integer.parseInt(str);
int n2 = Integer.parseInt(str2);
if(n1 > n2){
System.out.print(n1);
}
else{
System.out.print(n2);
}
}
}
5622번: 다이얼
첫째 줄에 알파벳 대문자로 이루어진 단어가 주어진다. 단어의 길이는 2보다 크거나 같고, 15보다 작거나 같다.
www.acmicpc.net
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
int count = 0;
for(int i=0; i<str.length(); i++){
switch(str.charAt(i)) {
case 'A' : case 'B': case 'C' :
count += 3;
break;
case 'D' : case 'E': case 'F' :
count += 4;
break;
case 'G' : case 'H': case 'I' :
count += 5;
break;
case 'J' : case 'K': case 'L' :
count += 6;
break;
case 'M' : case 'N': case 'O' :
count += 7;
break;
case 'P' : case 'Q': case 'R' : case 'S' :
count += 8;
break;
case 'T' : case 'U': case 'V' :
count += 9;
break;
case 'W' : case 'X': case 'Y' : case 'Z' :
count += 10;
break;
}
}
System.out.print(count);
}
}
10809번: 알파벳 찾기
각각의 알파벳에 대해서, a가 처음 등장하는 위치, b가 처음 등장하는 위치, ... z가 처음 등장하는 위치를 공백으로 구분해서 출력한다. 만약, 어떤 알파벳이 단어에 포함되어 있지 않다면 -1을 출
www.acmicpc.net
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
int[] ab = new int[26];
for(int i = 0; i<ab.length; i++){
ab[i] = -1;
}
for(int i = 0; i<str.length(); i++){
char c = str.charAt(i);
if(ab[c -'a'] == -1){
ab[c - 'a' ] = i;
}
}
for(int result : ab){
System.out.print(result+" ");
}
}
}
'JAVA' 카테고리의 다른 글
ep 07.문제 풀이 (0) | 2022.12.19 |
---|---|
ep 07. 기본 클래스 (0) | 2022.12.19 |
ep 06-1. Interface (0) | 2022.12.11 |
ep 05-2. 문제 풀이 (0) | 2022.12.02 |
ep 05-1.추상 클래스 (0) | 2022.12.02 |