반응형

윤년은 4의 배수이면서 100의 배수가 아니거나 400의 배수여야하니까
이중 if문을 사용해주면 되겠다고 판단했다
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int year;
cin >> year;
if (year % 4 == 0)
{
if (year % 100 != 0 || year % 400 == 0)
{
cout << 1;
}
}
else cout << 0;
return 0;
}
하지만 여기서 안 쪽 if문에서 else를 처리해주지 않아 오류가 발생했었다
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int year;
cin >> year;
if (year % 4 == 0)
{
if (year % 100 != 0 || year % 400 == 0)
{
cout << 1;
}
else cout << 0;
}
else cout << 0;
return 0;
}
반응형
'algorithm > 기초 코드' 카테고리의 다른 글
| [algorithm] 백준 10093번 숫자 (0) | 2025.10.12 |
|---|---|
| [algorithm] 백준 2480번 주사위 세개 (0) | 2025.10.12 |
| [algorithm] 백준 2752번 세수정렬 (0) | 2025.10.12 |
| [algorithm] 백준 9498번 시험 성적 (0) | 2025.10.12 |
| [algorithm] 백준 10869번 사칙연산 (0) | 2025.10.10 |
