[algorithm] 백준 2753번 윤년

2025. 10. 12. 11:00·algorithm/기초 코드
반응형

 

 

윤년은 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
'algorithm/기초 코드' 카테고리의 다른 글
  • [algorithm] 백준 10093번 숫자
  • [algorithm] 백준 2480번 주사위 세개
  • [algorithm] 백준 2752번 세수정렬
  • [algorithm] 백준 9498번 시험 성적
20puddle
20puddle
20puddle 님의 블로그 입니다.
  • 20puddle
    20puddle 님의 블로그
    20puddle
  • 전체
    오늘
    어제
    • 분류 전체보기 (100)
      • Spring boot (5)
      • git & github (5)
      • algorithm (47)
        • theory (3)
        • 배열 (7)
        • 연결 리스트 (3)
        • 스택 (5)
        • 큐 (3)
        • 덱 (2)
        • 기초 코드 (19)
        • BFS (5)
      • AI (43)
        • Machine Learning (35)
        • Deep Learning (8)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    오프라인 학습
    홀드아웃 검증
    머신러닝
    DL
    github
    Aimers
    그레디언트 클리핑
    알고리즘
    ML
    인공지능
    git
    딥러닝
    백준
    주성분변환
    AI
    Spring Boot
    연결리스트
    게시판
    list
    Java
  • 최근 댓글

  • 최근 글

  • 반응형
  • hELLO· Designed By정상우.v4.10.3
20puddle
[algorithm] 백준 2753번 윤년
상단으로

티스토리툴바