# Hardwood Species 題目連結 [UVa 10226](https://onlinejudge.org/external/102/10226.pdf) ## 中文簡述 輸入樹木的種類,輸出戰友的百分比 ## [think] 這題用map來處理,順道設一個變數`total`來記錄總數目 ## solution: ``` #include<bits/stdc++.h> using namespace std; int main() { map<string,int>trees; int n,total,i; while(cin>>n) { string str; cin.ignore(); getline(cin,str); // blank line; for(int cs=1;cs<=n;cs++) { trees.clear(); total=0; if(cs!=1) cout<<endl; while(getline(cin,str)) { if(str=="") break; trees[str]++; total++; } for(auto&i:trees) { printf("%s %.4f",i.first.c_str(),(double)i.second/total *100); cout<<endl; } } } } ``` ###### tags: `UVA` 回目錄 [學習筆記](/gIBZqAbWTCis7uOPp149gA)