문제번호
1330 두 수 비교하기
https://www.acmicpc.net/problem/1330
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int A = sc.nextInt();
int B = sc.nextInt();
sc.close();
if(A==B) {
System.out.println("==");
}else if(A<B) {
System.out.println("<");
}else if(A>B){
System.out.println(">");
}
}
9498 시험성적표
https://www.acmicpc.net/problem/9498
// Scanner sc = new Scanner(System.in);
//
// int A = sc.nextInt();
//
// sc.close();
//
// if(A>=90) {
// System.out.println("A");
// }else if(A>=80) {
// System.out.println("B");
// }else if(A>=70) {
// System.out.println("C");
// }else if(A>=60) {
// System.out.println("D");
// }else {
// System.out.println("F");
// }
BufferedReader 로 풀어도 됨.
2753 윤년
https://www.acmicpc.net/problem/2753
public static void main(String[] args) throws Exception, IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int A = Integer.parseInt(bf.readLine());
if((A % 4 == 0 && A % 100 != 0 )|| A % 400 == 0) {
System.out.println("1");
}else {
System.out.println("0");
}
}
}
4의 배수 표현은 A 나누기 4 == 0 일때 4의 배수,
마찬가지로 100의 배수도 100을 나눴을 때 0이 나오면 100의 배수로 표현하는 법을 알면
쉽게 풀수 있는 문제..라고 생각함.
14681 사분면
https://www.acmicpc.net/problem/14681
// Scanner sc = new Scanner(System.in);
//
// int X = sc.nextInt();
// int Y = sc.nextInt();
//
// sc.close();
//
// if(X>0) {
// if(Y>0) {
// System.out.println("1");
// }else {
// System.out.println("4");
// }
// }
// if(X<0) {
// if(Y>0) {
// System.out.println("2");
// }else {
// System.out.println("3");
// }
// }
양수와 음수 구별을 위한 if 문 문제인듯 합니다.
X가 양수일 때 (0보다 클 때)
이중 if 문으로 Y도 양수이면 1,
Y가 음수이면 4,
이런식의 표현입니다.
2884 알람시계
https://www.acmicpc.net/problem/2884
Scanner sc = new Scanner(System.in);
int H = sc.nextInt();
int M = sc.nextInt();
sc.close();
if(M < 45) {
H--;
M = 60 - (45 - M);
if(H < 0) {
H = 23;
}
System.out.println(H + " " + M);
}
else {
System.out.println(H + " " + (M-45));
}
}
알람문제이며, 시간(H)와 분(M)을 입력 값의 -45M 을 해주어야하는 문제입니다.
45분 이상일 시 M = 60-(45-M) 으로 45분만 빼주게 되고,
ex) 11시 50분 = > 11시 5분
45분 아래일 시 (M-45)을 해주면 됩니다.
모두 if문을 이용한 문제입니다.