πŸ•ΉοΈ μ½”λ”©ν…ŒμŠ€νŠΈ/μ½”λ“œνŠΈλ¦¬

[μ½”λ“œνŠΈλ¦¬/JAVA] μ’€ 더 μ–΄λ €μš΄ μˆ˜ν•™ 점수

Genie_. 2024. 9. 3. 21:39
728x90
λ°˜μ‘ν˜•

https://www.codetree.ai/missions/4/problems/math-scores-are-more-difficult?&utm_source=clipboard&utm_medium=text


λ‚΄ μ½”λ“œ

μš°μ„  학생 A와 Bκ°€ μžˆλ‹€.

A와 B의 μ˜μ–΄,μˆ˜ν•™μ μˆ˜λ₯Ό 각각 μž…λ ₯λ°›μ•„μ•Όν•œλ‹€ ( = Scanner)

쑰건 1. μ˜μ–΄ μ μˆ˜μ™€ 상관x μˆ˜ν•™ μ μˆ˜κ°€ λ†’μœΌλ©΄, 높은 학생 이름 좜λ ₯

쑰건 2. μˆ˜ν•™ μ μˆ˜κ°€ κ°™μœΌλ©΄ μ˜μ–΄ μ μˆ˜κ°€ 높은 ν•™μƒμ˜ 이름 좜λ ₯

단, μˆ˜ν•™ μ μˆ˜μ™€ μ˜μ–΄ μ μˆ˜κ°€ λ‘˜ λ‹€ λ™μΌν•˜κ²Œ μ£Όμ–΄μ§€λŠ” κ²½μš°λŠ” μ—†μŒ.

 

그럼 μž…λ ₯ λ°›μ•„μ•Όν•  μ μˆ˜κ°€ a의 μ˜μ–΄,μˆ˜ν•™ / b의 μ˜μ–΄, μˆ˜ν•™ 4κ°œλ‹€.

import java.util.Scanner;

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

        int bEng = sc.nextInt();
        int bMath = sc.nextInt();
    }
}

그리고 쑰건 1. μ˜μ–΄ μ μˆ˜μ™€ 상관x μˆ˜ν•™ μ μˆ˜κ°€ λ†’μœΌλ©΄, 높은 학생 이름 좜λ ₯

import java.util.Scanner;

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

        int bEng = sc.nextInt();
        int bMath = sc.nextInt();

        if ( aMath > bMath ){
            System.out.print("A");
        } else {
            System.out.print("B")
        }
    }
}

쑰건 2. μˆ˜ν•™ μ μˆ˜κ°€ κ°™μœΌλ©΄ μ˜μ–΄ μ μˆ˜κ°€ 높은 ν•™μƒμ˜ 이름 좜λ ₯

if ( aMath > bMath || (aMath == bMath) && (aEng > bEng)){

aκ°€ 쑰건1κ³Ό  쑰건2μ€‘μ—μ„œ ν•˜λ‚˜λΌλ„ λ§Œμ‘±ν•œλ‹€λ©΄ Aλ₯Ό 좜λ ₯

μ•„λ‹ˆλ©΄ Bλ₯Ό 좜λ ₯ν•˜λŠ” 걸둜 ν–ˆλ‹€.

κ·Έ κ³Όμ •μ—μ„œ if  else ifκΉŒμ§€λŠ” λ„ˆλ¬΄ μ½”λ“œκ°€ κΈΈμ–΄μ Έμ„œ, 짧게 λ‹€μ‹œ μ€„μ—¬λ³΄μ•˜λ‹€.

import java.util.Scanner;

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

        int bMath = sc.nextInt();
        int bEng = sc.nextInt();

        if ( aMath > bMath || (aMath == bMath) && (aEng > bEng)){
            System.out.print("A");
        } else {
            System.out.print("B");
        }
    }
}

그리고 λ¬Έμ œμ—μ„œ 

첫 번째 쀄에 A ν•™μƒμ˜ μˆ˜ν•™ μ μˆ˜μ™€ μ˜μ–΄ μ μˆ˜κ°€ 곡백을 사이에 두고 μ£Όμ–΄μ§‘λ‹ˆλ‹€.

두 번째 쀄에 B ν•™μƒμ˜ μˆ˜ν•™ μ μˆ˜μ™€ μ˜μ–΄ μ μˆ˜κ°€ 곡백을 사이에 두고 μ£Όμ–΄μ§‘λ‹ˆλ‹€.

μˆ˜ν•™ μ μˆ˜κ°€ λ¨Όμ € μž…λ ₯λ°›λŠ”λ‹€κ³  ν–ˆλŠ”λ°, λ‚˜λŠ” μ§€κΈˆ 이 μ½”λ“œλ§κ³  κ·Έ μœ„μ— μ½”λ“œλ₯Ό 보면 Engλ¨Όμ € μž…λ ₯ 받도둝 해놨닀.

κ·Έλž˜μ„œ 였λ₯˜κ°€ λ–΄λ‹€ ;-; μž…λ ₯ κ°’ μˆœμ„œλ„ ν•­μ‹œ ν™•μΈν•˜κΈ°.

ν…ŒμŠ€νŠΈ μ—¬λŸ¬λ²ˆ λŒλ Έμ„ λ•Œ 싀행에 λ¬Έμ œκ°€ μ—†μ–΄μ„œ 제좜


 

회고

처음 ν‹€λ¦°κ±°λŠ” μœ„μ— λ§ν–ˆλ“―μ΄, μž…λ ₯κ°’ μˆœμ„œλ₯Ό ν™•μΈν•˜μ§€ λͺ»ν•΄μ„œ μΌμ–΄λ‚œ 일!

항상 ν…ŒμŠ€νŠΈμ½”λ“œ μž…λ ₯ λ§Žμ΄ν•΄λ³΄κΈ°.

λ¬Έμ œλŠ” λ‘λ²ˆ μ„Έλ²ˆ 읽어보고 λΆ„μ„ν•˜κ³  μ°¨κ·Όμ°¨κ·Ό μ μ–΄μ„œ ν’€κΈ°

 


μ •λ‹΅

import java.util.Scanner;

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

        // λ³€μˆ˜ μ„ μ–Έ
        int a_math, a_eng;
        int b_math, b_eng;
        
        // μž…λ ₯
        a_math = sc.nextInt();
        a_eng = sc.nextInt();
        b_math = sc.nextInt();
        b_eng = sc.nextInt();

        // 좜λ ₯
        if(a_math > b_math || (a_math == b_math && a_eng > b_eng))
            System.out.println("A");
        else
            System.out.println("B");
    }
}
728x90
λ°˜μ‘ν˜•