굥뷰를 햡시댜
[BOJ-4358] 생태학 본문
https://www.acmicpc.net/problem/4358
풀고나서 알고리즘 분류를 봤더니 트라이로 구분되어 있었다.
나는 map을 사용했기 때문에 풀긴 풀었는데 정해는 아닌듯 하다.
- 풀이 방법
1. 입력을 받는다.
2. map에 문자열로 key값을 주면 자동으로 사전순으로 정렬된다.. 그래서 value값을 더했고
3. auto를 이용해 답을 구했다.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <map>
#include <string>
using namespace std;
map<string, int> m;
int main(void) {
string str;
int cnt = 0;
while (1) {
getline(cin, str);
if (str.length() == 0) break;
cnt += 1;
m[str] += 1;
}
for (auto it = m.begin(); it != m.end(); it++) {
double temp = ((double)it->second / cnt);
cout << it->first;
printf(" %0.4lf\n", temp*100);
}
getchar();
getchar();
return 0;
}
Comments