題意:
(from luckycat)
解法:
just use STL map。
TAG: STL, ad hoc
注意:
程式碼:
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: 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; | |
} |
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!