https://www.acmicpc.net/problem/9733
9733번: 꿀벌
각각의 일을 한 횟수와 비율을 공백으로 구분하여 출력한다. 출력은 {Re,Pt,Cc,Ea,Tb,Cm,Ex} 순서대로 하며, 비율은 소수점 둘째 자리까지 출력한다. 주어진 목록에 없는 일은 출력하지 않는다. 입력의
www.acmicpc.net
문제 해설
꿀벌이 하는 일들의 총 횟수, 각각의 횟수를 기록하고, 횟수와 전체 대비 비율을 출력하는 문제다.
#include <iostream>
#define fio cin.tie(0)->sync_with_stdio(0)
using namespace std;
#include <map>
#include <sstream>
#include <vector>
#include <iomanip>
int main(){
fio;
map<string, int> map_;
string S;
double total = 0;
while(getline(cin, S)){
stringstream ss(S);
while(ss >> S){
map_[S]++;
total += 1;
}
}
//
//cout << fixed << setprecision(4);
vector<string> work ={"Re","Pt","Cc","Ea","Tb","Cm","Ex"};
for(int i = 0; i < work.size(); i++){
string s = work[i];
if(map_.find(s) != map_.end()){
cout << s <<' ' << map_[s] << ' ';
cout << fixed << setprecision(2)<< map_[s]/total;
cout <<'\n';
}else{
cout << s <<' ' << 0 << ' ';
cout << "0.00";
cout <<'\n';
}
}
cout << "Total " << (int)total << " 1.00";
return 0;
}
'알고리즘 > 백준' 카테고리의 다른 글
백준 10689 Hamza (0) | 2021.12.27 |
---|---|
백준 10527 Judging Troubles (0) | 2021.12.27 |
백준 8641 Sklep (0) | 2021.12.27 |
백준 6973 Dynamic Dictionary Coding (0) | 2021.12.27 |
백준 6325 Definite Values (0) | 2021.12.27 |