BAEKJOON 문제 풀이 : 10817번 세 수
BAEKJOON2020. 1. 25. 11:28
문제 : https://www.acmicpc.net/problem/10817
10817번: 세 수
첫째 줄에 세 정수 A, B, C가 공백으로 구분되어 주어진다. (1 ≤ A, B, C ≤ 100)
www.acmicpc.net
주어진 세 정수 중 두 번째로 큰 수를 출력하는 문제입니다.
조건문을 이용해 풀었습니다.
문제풀이는 아래와 같습니다.
1. Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); String[] strNums = br.readLine().split(" ", -1); int a = Integer.parseInt(strNums[0]); int b = Integer.parseInt(strNums[1]); int c = Integer.parseInt(strNums[2]); if ((b >= a && a >= c) || (c >= a && a >= b)) { bw.write(a + "\n"); } else if ((a >= b && b >= c) || (c >= b && b >= a)) { bw.write(b + "\n"); } else { bw.write(c + "\n"); } bw.close(); br.close(); } } | cs |
2. Python3
1 2 3 4 5 6 7 8 | if __name__ == '__main__': num1, num2, num3 = map(int, input().split(' ', -1)) if ((num2 >= num1 and num1 >= num3) or (num3 >= num1 and num1 >= num2)): print(num1) elif ((num1 >= num2 and num2 >= num3) or (num3 >= num2 and num2 >= num1)): print(num2) else: print(num3) | cs |
'BAEKJOON' 카테고리의 다른 글
BAEKJOON 문제 풀이 : 15552번 빠른 A+B (0) | 2020.01.26 |
---|---|
BAEKJOON 문제 풀이 : 2739번 구구단 (0) | 2020.01.25 |
BAEKJOON 문제 풀이 : 2753번 윤년 (0) | 2020.01.21 |
BAEKJOON 문제 풀이 : 2588번 곱셈 (0) | 2020.01.20 |
BAEKJOON 문제 풀이 : 15792번 A/B - 2 (0) | 2020.01.19 |