반응형
[ 2753번 | 윤년 ]
https://www.acmicpc.net/problem/2753
[ C# ]
int y = int.Parse(Console.ReadLine());
if(y % 400 == 0) Console.Write(1);
else if(y % 100 == 0) Console.Write(0);
else if(y % 4 == 0) Console.Write(1);
else Console.Write(0);
[ Python ]
y = int(input())
if(y % 400 == 0): print(1)
elif(y % 100 == 0): print(0)
elif(y % 4 == 0): print(1)
else: print(0)
[ C ]
#include <stdio.h>
int main(){
int y;
scanf("%d", &y);
if(y % 400 == 0)printf("1");
else if(y % 100 == 0) printf("0");
else if(y % 4 == 0) printf("1");
else printf("0");
}
[ 14681번 | 사분면 고르기 ]
https://www.acmicpc.net/problem/14681
[ C# ]
int x = int.Parse(Console.ReadLine());
int y = int.Parse(Console.ReadLine());
if(x < 0){
if(y < 0) Console.Write('3');
else if(y > 0) Console.Write('2');
else return;
}
else if(x > 0){
if(y < 0) Console.Write('4');
else if(y > 0) Console.Write('1');
else return;
}
else return;
[ Python ]
x = int(input())
y = int(input())
if(x < 0):
if(y < 0): print(3)
elif(y > 0): print(2)
else: print('x')
elif(x > 0):
if(y < 0): print(4)
elif(y > 0): print(1)
else: print('x')
else: print('x')
[ C ]
#include <stdio.h>
int main(){
int x, y;
scanf("%d %d", &x, &y);
if(x < 0){
if(y < 0) printf("3");
else if(y > 0) printf("2");
else printf("x");
}
else if(x > 0){
if(y < 0) printf("4");
else if(y > 0) printf("1");
else printf("x");
}
else printf("x");
}
영점일 때는 뭘 출력하는지 문제에 나와있지 않아 x를 출력하도록 코드를 짜봤다.
반응형
'코딩 공부 > 백준 코딩테스트' 카테고리의 다른 글
[백준 코딩테스트] 2480번 | C, C#, Python (0) | 2023.04.07 |
---|---|
[백준 코딩테스트] 2884번, 2525번 | C, C#, Python (0) | 2023.04.07 |
[백준 코딩테스트] 1330번, 9498번 | C, C#, Python (0) | 2023.04.05 |
[백준 코딩테스트] 11382번, 10171번, 10172번 | C#, Python (0) | 2023.04.04 |
[백준 코딩테스트] 10430번, 2588번 | C#, Python (0) | 2023.04.04 |