# UVA 10226 - Hardwood Species ## Online Judge  ## 解題思路 要算樹種所佔的比例,並依照字母順序排列。 ## 解題中出現的bug 1.每組testcase是一行一行讀的直覺用getline來讀,但要注意testcase之間是用空行來做區隔的,小心不要被吃掉字串。 2.一開始沒想到用map,用vector還要排序......(眼神死 ## Code ```cpp= #include <iostream> #include <string> #include <iomanip> #include <map> using namespace std; int main() { int test_case = 0; cin >> test_case; getchar(); getchar(); while (test_case--) { int counter = 0; map <string, double> Hardwood; string tree; while (getline(cin, tree) && tree != "") { counter++; Hardwood[tree]++; } for (map<string, double>::iterator it = Hardwood.begin(); it != Hardwood.end(); it++) { cout << it->first << " " << setprecision(4) << fixed << it->second * 100.0 / counter << endl; } if (test_case) cout << endl; } return 0; } ``` ###### tags: `UVA code` `cpp` `林基成-C++` `Awwwolf的刷題之路`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up