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

2015年6月11日 星期四

[UVa] 10295 - Hay Points

題目網址: https://goo.gl/lbCF8R

題意:
(from luckycat)


解法:
just use STL map。

TAG: STL, ad hoc

注意:

程式碼:
/**
* Tittle: 10295 - Hay Points
* Author: Cheng-Shih, Wong
* Date: 2015/06/11
*/
// include files
#include <bits/stdc++.h>
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 unordered_map<string,int> MSI;
// declarations
int m, n;
MSI dict;
// functions
// main function
int main( void )
{
string ts;
int v, ans;
// input
while( scanf( "%d%d", &m, &n )==2 ) {
dict.clear();
FOR( i, 1, m ) {
cin >> ts >> v;
dict[ts] = v;
}
FOR( i, 1, n ) {
ans = 0;
while( cin>>ts && ts!="." )
ans += dict[ts];
printf( "%d\n", ans );
}
}
return 0;
}

1 則留言:

  1. The following url is more detail about your problem!
    http://stackoverflow.com/questions/25311011/how-does-include-bits-stdc-h-work-in-c

    Or you can simply replace eighth line "#include " with the exact libraries you needed!

    回覆刪除

任何意見都樂意傾聽