[1330번] 1. 두 수 비교하기
C++
#include <iostream>
int main()
{
int A, B;
std::cin >> A >> B;
if(A>B) {
std::cout << ">";
}
else if(A<B) {
std::cout << "<";
}
else {
std::cout << "==";
}
}
Python
A, B = list(map(int, input().split()))
if A > B: print(">")
elif A < B: print("<")
else: print("==")
[9498번] 2. 시험 성적
C++
#include <iostream>
int main()
{
int score;
std::cin >> score;
if(score >= 90) {
std::cout << 'A';
}
else if(score >= 80) {
std::cout << 'B';
}
else if(score >= 70) {
std::cout << 'C';
}
else if(score >= 60) {
std::cout << 'D';
}
else {
std::cout << 'F';
}
return 0;
}
Python
score = int(input())
if score >= 90: print("A")
elif score >= 80: print("B")
elif score >= 70: print("C")
elif score >= 60: print("D")
else: print("F")
[2753번] 3. 윤년
C++
#include <iostream>
int main()
{
int year;
std::cin >> year;
if((year % 4 == 0) && (year % 100 != 0 || year % 400 == 0)) {
std::cout << "1";
}
else {
std::cout << "0";
}
return 0;
}
Python
year = int(input())
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
print(1)
else:
print(0)
[14681번] 4. 사분면 고르기
C++
#include <iostream>
int main()
{
int x, y;
std::cin >> x;
std::cin >> y;
if(x>0) {
if(y>0) {
std::cout << "1";
}
else {
std::cout << "4";
}
}
else {
if(y>0) {
std::cout << "2";
}
else {
std::cout << "3";
}
}
return 0;
}
Python
x, y = int(input()), int(input())
if x > 0:
if y > 0:
print("1")
else:
print("4")
else:
if y > 0:
print("2")
else:
print("3")
[2884번] 5. 알림 시계
C++
#include <iostream>
int main()
{
int H, M;
std::cin >> H >> M;
if(M <45) {
H -= 1;
M = 60 - (45 - M);
if(H == -1) {
H = 23;
}
}
else {
M -= 45;
}
std::cout << H << " " << M;
return 0;
}
Python
H, M = list(map(int, input().split()))
if M < 45:
H -= 1
M = 60 - (45 - M)
if H == -1:
H = 23
else:
M = M - 45
print("{} {}".format(H, M))
[2525번] 6. 오븐 시계
C++
#include <iostream>
int main()
{
int H, M, time;
std::cin >> H >> M;
std::cin >> time;
H += time / 60;
M += time % 60;
H += M / 60;
M = M % 60;
if(H % 24 ==0) {
H = 0;
}
else {
H %= 24;
}
std::cout << H << " " << M;
}
Python
H, M = list(map(int, input().split()))
time = int(input())
H += time // 60
M += time % 60
H += M // 60
M = M % 60
if H % 24 ==0: H = 0
else: H %= 24
print("{} {}".format(H, M))
[2480번] 7. 주사위 세게
C++
#include <iostream>
#include <algorithm>
int main()
{
int x, y, z;
std::cin >> x >> y >> z;
if(x == y || x == z || y == z) {
if(x == y && x == z) {
std::cout << 10000 + x * 1000;
}
else if(x == y || x == z) {
std::cout << 1000 + x * 100;
}
else {
std::cout << 1000 + y * 100;
}
}
else {
std::cout << std::max({x, y, z}) * 100;
}
return 0;
}
Python
x, y, z = list(map(int, input().split()))
if x == y or x == z or y == z:
if x == y and y == z:
print(10000 + x * 1000)
elif x == y or x == z:
print(1000 + x * 100)
else:
print(1000 + y * 100)
else:
print(max(x, y, z)*100)