티스토리 뷰


title: "달팽이는 올라가고 싶다(2869)"
category: 백준[Class-2]
tags: [C++, JavaScript, 백준]
date: "2021-03-18"


문제 링크

달팽이는 올라가고 싶다(2869)

C++

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

// 문제 풀이 함수
void solution(){
    int a, b, v;
    cin >> a >> b >> v;

    if(v>a){
        cout<<(int)ceil((double)(v-a)/(a-b))+1<<endl;
    }
    else{
        // 하루만에 올라감
        cout<<1<<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(" ");

// 문제 풀이
const a = +input[0];
const b = +input[1];
const v = +input[2];

if (v > a) {
  console.log(Math.ceil((v - a) / (a - b)) + 1);
} else {
  console.log(1);
}
728x90
반응형

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

[백준] 단어 정렬(1181)  (0) 2021.03.19
[백준] 체스판 다시 칠하기(1018)  (0) 2021.03.19
[백준] 설탕 배달(2839)  (0) 2021.03.18
[백준] Hashing(15829)  (0) 2021.03.18
[백준] 부녀회장이 될테야(2775)  (0) 2021.03.18
댓글
05-09 17:48
링크