티스토리 뷰


title: "ACM 호텔(10250)"
category: 백준[Class-2]
tags: [C++, JavaScript, 백준]
date: "2021-03-16"


문제 링크

ACM 호텔(10250)

C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

// 문제 풀이 함수
void solution(){
    int a, h, w, n;
    cin >> a;
    while(cin >> h >> w >> n){
        int first = n % h;
        first = first==0 ? h : first;

        int last = n / h;
        last = first!=h ? last+1 : last;

        if(last<10)
            cout<<first<<"0"<<last<<endl;
        else
            cout<<first<<last<<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];

for (let i = 1; i <= n; i++) {
  const hwn = input[i].split(" ");
  const h = +hwn[0];
  const w = +hwn[1];
  const n = +hwn[2];

  let first = n % h;
  first = first === 0 ? h : first;

  let last = Math.ceil(n / h);
  last = last < 10 ? "0" + last : last;

  console.log(`${first}${last}`);
}
728x90
반응형

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

[백준] 수 정렬하기(2750)  (0) 2021.03.18
[백준] 이항 계수 1(11050)  (0) 2021.03.18
[백준] 블랙잭(2798)  (0) 2021.03.18
[백준] 직각삼각형(4153)  (0) 2021.03.16
[백준] 직사각형에서 탈출(1085)  (0) 2021.03.16
댓글
05-20 13:38
링크