![[백준 / BOJ] 2753번 윤년 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbtGGYB%2FbtrLvCr0OAB%2FlJ56K07I030OOqSj9gfMe0%2Fimg.jpg)
[백준 / BOJ] 2753번 윤년 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2021. 8. 21. 01:51
반응형
링크 : https://www.acmicpc.net/problem/2753
2753번: 윤년
연도가 주어졌을 때, 윤년이면 1, 아니면 0을 출력하는 프로그램을 작성하시오. 윤년은 연도가 4의 배수이면서, 100의 배수가 아닐 때 또는 400의 배수일 때이다. 예를 들어, 2012년은 4의 배수이면서
www.acmicpc.net
문제

문제 풀이
C++ 상세 풀이
C++ 풀이 펼쳐보기
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
std::cout << '1';
else
std::cout << '0';
윤년은 연도가 4의 배수이면서, 100의 배수가 아닐 때 또는 400의 배수일 때 라고 주어졌으므로, % 연산을 이용하여 우선 4의 배수임을 판정한 후, 100의 배수가 아닐 때 또는 400의 배수일 때의 조건을 더 넣어주면 된다.
Python 상세 풀이
Python 풀이 펼쳐보기
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
print("1")
else:
print("0")
윤년은 연도가 4의 배수이면서, 100의 배수가 아닐 때 또는 400의 배수일 때 라고 주어졌으므로, % 연산을 이용하여 우선 4의 배수임을 판정한 후, 100의 배수가 아닐 때 또는 400의 배수일 때의 조건을 더 넣어주면 된다.
코드 전문
C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
void init() { | |
std::ios_base::sync_with_stdio(false); | |
std::cin.tie(nullptr); | |
std::cout.tie(nullptr); | |
} | |
int main() { | |
init(); | |
int var; | |
std::cin >> var; | |
if (var % 4 == 0 && (var % 100 != 0 || var % 400 == 0)) | |
std::cout << "1"; | |
else | |
std::cout << "0"; | |
return 0; | |
} |
+ 이전 풀이
더보기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
input = sys.stdin.readline | |
if __name__ == "__main__": | |
var = int(input()) | |
if var % 4 == 0 and (var % 100 != 0 or var % 400 == 0): | |
print("1") | |
else: | |
print("0") |
+ 이전 풀이
더보기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
소감
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 10950번 A+B - 3 (C++, Python) (0) | 2021.08.22 |
---|---|
[백준 / BOJ] 2739번 구구단 (C++, Python) (0) | 2021.08.22 |
[백준 / BOJ] 2884번 알람 시계 (C++, Python) (0) | 2021.08.22 |
[백준 / BOJ] 14681번 사분면 고르기 (C++, Python) (0) | 2021.08.22 |
[백준 / BOJ] 9498번 시험 성적 (C++, Python) (0) | 2021.08.21 |
@Reo :: 코드 아카이브
자기계발 블로그