※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 6830번 문제인 It's Cold Here!이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/6830
6830번: It’s Cold Here!
Canada is cold in winter, but some parts are colder than others. Your task is very simple, you need to find the coldest city in Canada. So, when given a list of cities and their temperatures, you are to determine which city in the list has the lowest tempe
www.acmicpc.net
주어지는 도시이름과 그 도시의 기온마다 이 도시의 기온이 지금까지 나온 도시의 기온보다 낮은지를 확인해 더 낮다면 해당 도시를 기록하는 것을 반복하는 것으로 문제를 해결할 수 있다.
모든 (온도, 도시이름) 쌍을 벡터에 집어넣고 온도 오름차순으로 정렬해도 문제를 해결할 수 있을 것이다.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
string ans; int temp = 222;
string s; int i;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
while (cin >> s >> i) {
if (i < temp) ans = s, temp = i;
}
cout << ans;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 6889 // C++] Smile with Similes (0) | 2022.12.22 |
---|---|
[BOJ 5343 // C++] Parity Bit (0) | 2022.12.22 |
[BOJ 4327 // C++] Combination Lock (0) | 2022.12.22 |
[BOJ 26587 // C++] Reverse (0) | 2022.12.22 |
[BOJ 5340 // C++] Secret Location (0) | 2022.12.22 |