[백준 / java 11] 조건문 > 1330번, 9498번, 2753번, 14681번, 2884번, 2525번, 2480번

2025. 4. 28. 10:45·코테/백준

#1330 두 수 비교하기

 

 

* 풀이

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        if(A > B){
            System.out.print(">");
        } else if(A < B){
            System.out.print("<");
        } else{
            System.out.print("==");
        }
    }
}

 

 


 

 

# 9498 시험 성적

 

 

* 풀이

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int score = sc.nextInt();
        
        if(90 <= score && score <= 100){
            System.out.print("A");
        } else if(80 <= score && score < 90){
            System.out.print("B");
        } else if(70 <= score && score < 80){
            System.out.print("C");
        } else if(60 <= score && score < 70){
            System.out.print("D");
        } else{
            System.out.print("F");
        }
        
    }
}

 

 


 

 

# 2754 윤년

 

 

* 풀이

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int year = sc.nextInt();
        
        if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)){
                System.out.print("1");
            } else{
            System.out.print("0");
            } 
    }
}

 

 


 

 

# 14681 사분면 고르기

 

 

 

* 풀이

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        
        if(x > 0 && y > 0){
            System.out.print("1");
        } else if(x < 0 && y > 0){
            System.out.print("2");
        } else if(x < 0 && y < 0){
            System.out.print("3");
        } else if(x > 0 && y < 0){
            System.out.print("4");
        }
    }
}

 

 


 

 

# 2884 알람시계

 

 

* 풀이

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt();
        int m = sc.nextInt();

        if (m < 45) {
            h--;
            m = m + 60 - 45;
            
            if (h < 0) {
                h = 23;
            }
        } else {
            m = m - 45;
        }

        System.out.println(h + " " + m);
    }
}

if (minute < 45) {
             hour = hour - 1;

현재 분에서 45를 빼서 음수가 됐을 때 시(h)도 1시간 줄여야 함


if (hour < 0) {
             hour = 23;

시(h)가 음수가 되면 23시로 (자정 바로 전)

 

else문

그냥 분에서 45를 빼면 됨

 

 

* 다른 풀이

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt(); // 시
        int M = sc.nextInt(); // 분
        sc.close();

        if (M >= 45) {
            M -= 45;
        } else {
            H -= 1;     // 한 시간 감소
            M += 15;    // 60 - 45 = 15 더하기
            if (H < 0) { // 0시에서 1시간 빼면 -1 → 23시 처리
                H = 23;
            }
        }

        System.out.println(H + " " + M);
    }
}

 


 

 

# 2525 오븐 시계

 

 

* 풀이

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        int min = (a * 60) + b;
        min += c;
        
        a = min / 60;
        b = min % 60;
        
        if(a > 23){
            a = a - 24;
        }
        System.out.print(a + " " + b);
    }
}

시를 분으로 바꾼 후 다 더한 다음에 60으로 다시 나눴다.

if문을 통해 시가 24 이상일 경우 24를 빼서 0, 1 ~~ 시가 될 수 있도록 한다.

 

 

* 다른 풀이

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt(); // 현재 시
        int b = sc.nextInt(); // 현재 분
        int c = sc.nextInt(); // 요리 시간 (분 단위)

        // 총 분 계산
        int totalMin = A * 60 + B + C;

        // 종료 시각
        int H = totalMin / 60;
        int M = totalMin % 60;

        if (H >= 24) {
            H = H % 24; // 24시 넘으면 0시로 환산
        }

        System.out.println(H + " " + M);
    }
}

 

 

# 2480 주사위 세개

 

 

* 풀이

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if(a == b && b == c){
            System.out.print(10000 + a * 1000);
        } else if(a == b || a == c){
            System.out.print(1000 + a * 100);
        } else if(b == c){
            System.out.print(1000 + b * 100);
        } else{
            int max = a;
            if(max < b){
                max = b;
            }if(max < c){
                max = c;
            }
            System.out.print(max * 100);
        }
        
    }
}

 

 

 

 

 

저작자표시 비영리 변경금지 (새창열림)

'코테 > 백준' 카테고리의 다른 글

[백준 / java 11] 2741번 N 찍기  (0) 2025.05.01
[백준 / java 11] 반복문 > 2739번 구구단  (0) 2025.04.29
[백준 / java 11] 입출력과 사칙연산 > 10926번, 18108번, 10430번, 11382번, 10171번, 10172번  (0) 2025.04.27
[백준 / java 11] 입출력과 사칙연산 > 1008번 A/B  (0) 2025.04.24
[백준 / java 11] 입출력과 사칙연산 > 1000 A+B, 1001 A-B, 2258 A+B -2  (0) 2024.11.14
'코테/백준' 카테고리의 다른 글
  • [백준 / java 11] 2741번 N 찍기
  • [백준 / java 11] 반복문 > 2739번 구구단
  • [백준 / java 11] 입출력과 사칙연산 > 10926번, 18108번, 10430번, 11382번, 10171번, 10172번
  • [백준 / java 11] 입출력과 사칙연산 > 1008번 A/B
amying
amying
공부해보겠슨
  • amying
    꽁꽁 얼어붙은 자바 위를 자박자박
    amying
  • 글쓰기 관리
  • 전체
    오늘
    어제
    • 분류 전체보기 (332)
      • 공부 (55)
        • JAVA (17)
        • Spring (17)
        • Java Script (1)
        • React (0)
        • SQL (3)
        • DB (1)
        • CS (13)
        • 기술면접 (3)
      • Git (2)
      • 강의 (36)
        • 부스트코스: Connect On: 테크와 나를 잇.. (16)
        • 부스트코스: CS50 (20)
      • 네이버 부스트캠프 베이직 (25. 06) (0)
      • 에러 (10)
      • 코테 (205)
        • 백준 (29)
        • 프로그래머스 JAVA Lv.0 (116)
        • 프로그래머스 JAVA Lv.1 (7)
        • 프로그래머스 SQL (53)
      • 개인 프로젝트 (16)
        • 책첵 CHAEKCHECK (2)
        • 일정 관리 서비스 만들기 (0)
        • 게시판 만들기 (eclipse-JSP) (14)
      • 이것저것 (4)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    CS50
    ORACLE에러
    오라클에러
    알고리즘
    업무자동화
    코테
    Java
    에러
    부스트코스
    프로그래머스
    코딩테스트_입문
    책첵개발일지
    git명령어
    데이터연동
    springbot
    부스트코스강의
    lombok
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.4
amying
[백준 / java 11] 조건문 > 1330번, 9498번, 2753번, 14681번, 2884번, 2525번, 2480번
상단으로

티스토리툴바