일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- 백준
- BOJ
- SW Expert Academy
- 법의학
- cs
- 자료구조
- D3
- 네트워크
- algorithm
- db
- OS
- algogritim
- 운영체제
- 데이터베이스
- language
- 감상문
- LeetCode
- 알고리즘
- network
- Computer Science
- Programmers
- 문제풀이
- 재테크/투자
- data structure
- Database
- D2
- 독서
- swea
- c++
- 프로그래머스
Archives
- Today
- Total
선택은 나의 것
[BOJ 백준] 4358번 생태학 본문
문제
BOJ 4358 : www.acmicpc.net/problem/4358
4358번: 생태학
프로그램은 여러 줄로 이루어져 있으며, 한 줄에 하나의 나무 종 이름이 주어진다. 어떤 종 이름도 30글자를 넘지 않으며, 입력에는 최대 10,000개의 종이 주어지고 최대 1,000,000그루의 나무가 주어
www.acmicpc.net
접근
map을 사용하여 중복으로 등장하는 나무의 그루 수를 세준다. map은 오름차순 정렬이 되어있기 때문에 순차적으로 출력하며 몇%를 차지하는지 계산해주면 된다.
코드
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
string s;
map<string, double> m;
double counter = 0;
while (getline(cin, s)) {
counter++;
if (m.find(s) == m.end())
m.insert(make_pair(s, 1));
else
m[s]++;
}
cout.setf(ios::fixed);
cout.precision(4);
for (auto it = m.begin(); it != m.end(); it++) {
double num = it->second / counter * 100;
cout << it->first << " " << num << "\n";
}
}
'☽ Algorithm > BOJ' 카테고리의 다른 글
[BOJ 백준] 11720번 숫자의 합 (Python) (0) | 2020.09.05 |
---|---|
[BOJ 백준] 16172번 나는 친구가 적다(Large) (Python) (0) | 2020.09.03 |
[BOJ 백준] 2839번 설탕 배달 (0) | 2020.08.24 |
[BOJ 백준] 1152번 단어의 개수 (Python) (0) | 2020.08.18 |
[BOJ 백준] 2577번 숫자의 개수 (Python) (0) | 2020.08.17 |
Comments