我是個對電腦科學有興趣的學生,我會貼上我的學習歷程及生活心情,也請大大們多多指教。 :)

2015年5月22日 星期五

[UVa] 10226 - Hardwood Species

題目網址: http://goo.gl/2M8sCv

題意:
(from luckycat)


解 法: 用 map 統計。

TAG: STL

注意:

程式碼:
/**
* 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;
}

沒有留言:

張貼留言

任何意見都樂意傾聽