반응형
https://www.acmicpc.net/problem/6162
6162번: Superlatives
Typically, droughts are classified into “abnormally dry”, “moderate drought”, “severe drought”, “extreme drought”, and “exceptional drought”. The current drought is so “exceptional” in most of California that there have been discuss
www.acmicpc.net
구현문제였습니다.
📕 풀이방법
📔 입력 및 초기화
1. 테스트 케이스 개수 t를 선언 후 입력해줍니다. 2. t만큼 for loop를 수행하며 expected, actual을 선언해 입력해줍니다.
📔 풀이과정
조건에 맞는 string을 반환하는 함수 getWetherString을 수행해줍니다. expected미만일 때까지 actual * 5 부터 시작해 5배씩 곱하며 mega를 붙여준 결과를 반환해줍니다.
📔 정답출력
출력형식에 맞게 출력해줍니다.
📕 Code
#include <bits/stdc++.h>
using namespace std;
int t;
string getWetherString(int expected, int actual) {
if(expected <= actual) return "no drought";
string base = "drought", d;
for(int i = actual*5; i < expected; i *= 5) d += "mega ";
return d + base;
}
int main(){
cin >> t;
for(int i = 1; i <= t; i++){
int expected, actual;
cin >> expected >> actual;
cout << "Data Set " << i << ':' << '\n';
cout << getWetherString(expected, actual) << '\n';
cout << '\n';
}
}
'Algorithm > Implementation' 카테고리의 다른 글
(C++) - 백준(BOJ) 6249 : TV Reports (0) | 2021.12.23 |
---|---|
(C++) - 백준(BOJ) 6190 : Another Cow Number Game (0) | 2021.12.22 |
(C++) - 백준(BOJ) 6138 : Speed Reading (0) | 2021.12.20 |
(C++) - 백준(BOJ) 6060 : Wheel Rotation (0) | 2021.12.19 |
(C++) - 백준(BOJ) 5751 : Head or Tail (0) | 2021.12.18 |