코딩 공부/백준 코딩테스트

[백준 코딩테스트] 2753번, 14681번 | C, C#, Python

maintain_H 2023. 4. 5. 17:57
반응형

[ 2753번 | 윤년 ]

https://www.acmicpc.net/problem/2753

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를 출력하도록 코드를 짜봤다.

반응형