Search
Duplicate
📕

생태학

주차
문제번호
4358
언어
C++
티어
실버
유형
자료구조
문자열
해시를 사용한 집합과 맵
트리를 사용한 집합과 맵
nj_Blog
nj_상태
이해도
33%
풀이
사람
이해도 2
13 more properties

문제접근

맵 자료구조를 사용하여 key와 value를 생성해두고 순회하면서 비율 계산

놓쳤던 부분

EOF가 입력될때까지 입력 받기 위해서는 getline 사용
소수점 4자리 반올림을 위해 fixed, precision 사용
map 사용할때 key에 접근해보고 해당 키가 없으면 알아서 삽입해줌

코드

2292 KB

172 ms

#include <iostream> #include <string> #include <map> using namespace std; int main(void) { string input; map<string, double> m; int count = 0; ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); while (getline(cin, input)) { count++; m[input]++; } cout << fixed; cout.precision(4); for (auto it = m.begin(); it != m.end(); it++) cout << it->first << " " << it->second * 100 / count << "\n"; return (0); }
C++
복사