題意:
(from luckycat)
解 法: 用 map 統計。
TAG: STL
注意:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tittle: 10226 - Hardwood Species | |
* Author: Cheng-Shih, Wong | |
* Date: 2015/05/22 | |
*/ | |
// include files | |
#include <iostream> | |
#include <cstdio> | |
#include <cstring> | |
#include <map> | |
#include <string> | |
using namespace std; | |
// definitions | |
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i ) | |
#define clr(x,v) memset( x, v, sizeof(x) ) | |
typedef map<string,int> MSI; | |
// declarations | |
int t; | |
MSI trees; | |
// functions | |
// main function | |
int main( void ) | |
{ | |
string tmps; | |
int cnt; | |
// input | |
scanf( "%d", &t ); | |
getline( cin, tmps ); | |
getline( cin, tmps ); | |
while( t-- ) { | |
trees.clear(); | |
cnt = 0; | |
// input | |
while( getline( cin, tmps ) && tmps!="" ) { | |
++trees[tmps]; | |
++cnt; | |
} | |
// output | |
for( MSI::iterator it=trees.begin(); it != trees.end(); ++it ) | |
printf( "%s %.4lf\n", (*it).first.c_str(), ((*it).second*100.0)/cnt ); | |
if( t ) putchar('\n'); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽