https://www.acmicpc.net/problem/4358
4358번: 생태학
프로그램은 여러 줄로 이루어져 있으며, 한 줄에 하나의 나무 종 이름이 주어진다. 어떤 종 이름도 30글자를 넘지 않으며, 입력에는 최대 10,000개의 종이 주어지고 최대 1,000,000그루의 나무가 주어
www.acmicpc.net
#include <iostream>
#include <string>
#include <map>
#include <string.h>
using namespace std;
int main()
{
int i = 0;
map<string, int> m;
char tree[31];
int ch = 0;
int k = 0;
while (!cin.eof())
{
cin.getline(tree, 31, '\n');
k++;
if (m.find(tree) == m.end())
{
m.insert({ tree, 1});
}
else
{
(m.find(tree)->second)++;
}
}
k -= 1;
for (auto iter = m.begin(); iter != m.end(); iter++)
{
if (iter->first == "")
continue;
cout << iter->first;
int cnt = iter->second;
float per = (float)cnt / (float)k * (float)100;
printf(" %.4f\n", per);
}
return 0;
}
728x90
'코테 > 백준 문제풀이' 카테고리의 다른 글
백준 1987 알파벳 (0) | 2021.08.16 |
---|---|
백준 1697 숨바꼭질 (1) | 2021.08.12 |
백준 2002 추월 (0) | 2021.08.04 |
백준 9934 완전이진트리 (0) | 2021.08.03 |
백준 2220 힙정렬 (1) | 2021.07.22 |