본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 3512 : Flat

반응형

https://www.acmicpc.net/problem/3512

 

3512번: Flat

You are one of the developers of software for a real estate agency. One of the functions you are to implement is calculating different kinds of statistics for flats the agency is selling. Each flat consists of different types of rooms: bedroom, bathroom, k

www.acmicpc.net

출력을 신경써야하는 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

방 종류별 크기의 합을 저장할 map 변수 sizePerType, 방 개수 n, 1제곱당 가격 c, 전체 방 크기 totalSize, 각 방의 크기 sz, 방 종류 type을 선언 후 입력받습니다.

📔 풀이과정

매 방의 크기와 종류를 입력받을 때 마다 map에 해당 방에 대한 크기를 누적해 더해줍니다. 이후 totalSize에 해당 방의 크기를 더해줍니다.

📔 정답출력

출력형식에 맞춰 출력해줍니다. 마지막 정답은 소수점 6째자리까지 출력해줍니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;

map <string, double> sizePerType;
double n, c, totalSize, sz;
string type;

int main(){
  cin >> n >> c;

  while(n--){
    cin >> sz >> type;
    sizePerType[type] += sz;
    totalSize += sz;
  }
  
  cout << totalSize << '\n' << sizePerType["bedroom"] << '\n';
  printf("%.6f\n", c * (totalSize - sizePerType["balcony"]/2));
}

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.