문제
두 정수 A와 B가 주어졌을 때, A와 B를 비교하는 프로그램을 작성하시오.
입력
첫째 줄에 A와 B가 주어진다. A와 B는 공백 한 칸으로 구분되어 있다.
출력
첫째 줄에 다음 세 가지 중 하나를 출력한다.
- A가 B보다 큰 경우에는 '
>
'를 출력한다. - A가 B보다 작은 경우에는 '
<
'를 출력한다. - A와 B가 같은 경우에는 '
==
'를 출력한다.
제한
- -10,000 ≤ A, B ≤ 10,000
예제 입력 1
1 2
예제 출력 1
<
예제 입력 2
10 2
예제 출력 2
>
예제 입력 3
5 5
예제 출력 3
==
#문제 풀이 방법
두 수를 받으면 비교하는 문제다. 비교 연산자만 잘 사용하면 쉽게 풀 수 있을 것이다.
#C
#include <stdio.h>
int main(){
int a,b;
scanf("%d %d",&a,&b);
if(a>b){
printf(">");
}
else if(a<b){
printf("<");
}
else{
printf("==");
}
return 0;
}
#C++
#include <iostream>
using namespace std;
int main() {
int a;
int b;
cin >> a >> b;
if (a > b)
{
cout << ">" << endl;
}
else if (b > a)
{
cout << "<" << endl;
}
else
{
cout << "==" << endl;
}
return 0;
}
#Python
A, B = map(int,input().split())
if A>B:
print(">")
elif A<B:
print("<")
elif A==B:
print("==")
반응형
'PS > 백준' 카테고리의 다른 글
[백준/Baekjoon]<2475번> 검증수 [C/C++/Python][Class 1] (0) | 2022.07.08 |
---|---|
[백준/Baekjoon]<2438번> 별 찍기 - 1 [C/C++/Python][Class 1] (0) | 2022.07.07 |
[백준/Baekjoon]<1008번> A/B [C/C++/Python][Class 1] (0) | 2022.07.05 |
[백준/Baekjoon]<1001번> A-B [C/C++/Python][Class 1] (0) | 2022.07.04 |
[백준/Baekjoon]<1000번> A+B [C/C++/Python][Class 1] (0) | 2022.07.03 |