728x90
반응형
- 풀이 링크:
GitHub - xhaktmchl/Algorithm_study: 알고리즘 이론 및 문제풀이
알고리즘 이론 및 문제풀이. Contribute to xhaktmchl/Algorithm_study development by creating an account on GitHub.
github.com
#include <iostream>
#include <algorithm>
#include <map> // 중복 x
#include <string> // getline
using namespace std;
/*
[백준 4358 c++ V] 생태학
문제:
접근: 나무이름에 따른 갯수저장 ->해시 mao stl이용
시간복잡도:
풀이:
//1.나무 입력
//2.소수점 자리 고정
//3.비율 계산
*/
map<string, float> m;
string tree;
int cnt = 0;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
while (getline(cin, tree)) {
if (m.find(tree) != m.end()) {
m[tree] += 1;
}
else m[tree] = 1;
cnt++;
}
// 비율 계산
cout << fixed;
cout.precision(4);
for (auto it = m.begin(); it != m.end(); it++) {
float per= (it->second * 100) / cnt;
cout << it->first << " ";
cout << per << '\n';
}
return 0;
}
반응형
'Algorithm_BOJ(백준) > 구현(자료구조)(Data structure)' 카테고리의 다른 글
[백준 1927 c++ V] 최소 힙 (0) | 2021.09.06 |
---|---|
[백준 11279 c++ O] 최대 힙 (0) | 2021.09.06 |
[백준 20301 c++ O] 반전 요세푸스 (0) | 2021.08.31 |
[백준 18115 c++ V] 카드 놓기 (0) | 2021.08.30 |
[백준 3078 c++ V] 좋은 친구 (0) | 2021.08.30 |