티스토리 뷰

Baekjoon Solutions/Class-1

[백준] 윤년(2753)

률무차 2021. 3. 15. 19:42

title: "윤년(2753)"
category: 백준[Class-1]
tags: [C++, JavaScript, 백준]
date: "2021-03-15"


문제 링크

윤년(2753)

C++

#include <iostream>
#include <map>

using namespace std;

// 문제 풀이 함수
void solution(){
    int n;
    cin >> n;
    if(n%4==0 && (n%100!=0 || n%400==0)){
        cout<<1<<endl;
    }
    else{
        cout<<0<<endl;
    }
}

bool exists(const char* fileName){
    FILE* fp;
    if((fp = fopen(fileName, "r"))){
        fclose(fp);
        return true;
    }
    return false;
}

int main() {
    if(exists("stdin")){
        freopen("stdin", "r", stdin);
        solution();
        fclose(stdin);
    }
    else{
        solution();
    }

    return 0;
}

JavsScript

const fs = require("fs");
// split 조절
const input = fs.readFileSync("dev/stdin").toString().trim().split("\n");

// 문제 풀이
const n = input[0];
if (n % 4 === 0 && (n % 100 !== 0 || n % 400 === 0)) {
  console.log(1);
} else {
  console.log(0);
}
728x90
반응형

'Baekjoon Solutions > Class-1' 카테고리의 다른 글

[백준] 상수(2908)  (0) 2021.03.15
[백준] 알람 시계(2884)  (0) 2021.03.15
[백준] 기찍 N(2742)  (0) 2021.03.15
[백준] N 찍기(2741)  (0) 2021.03.14
[백준] 숫자의 개수(2577)  (0) 2021.03.14
댓글
05-17 21:49
링크