链接http://acm.hdu.edu.cn/showproblem.php?pid=5774
思路
打表好么好用的东西以前居然不太会用
//打表过程
void make()
{
ios_base::sync_with_stdio(false); //加速cin,cout
for(int i=0;i<70;i++)
{
//读取无效的年份和空格
string s;
scanf("%s",c);
getchar();//c++标准库居然没有trim函数
//读取获胜队伍名
gets(c);
s=c;
m[s]++;
}
for(it=m.begin();it!=m.end();it++)
printf("m[\"%s\"]=%d;\n",it->first.c_str(),it->second);
//cout<<"m[\""<<it->first<<"\"]="<<it->second<<";"<<endl;
}
解题代码
#include<ctype.h>
#include<algorithm>
#include<string.h>
#include<cstdio>
#include<iostream>
#include<string>
#include<map>
using namespace std;
map<string,int>m;
map<string,int>::iterator it;
char c[100];
//打表结果
void solve(){
m["Baltimore Bullets"]=1;
m["Boston Celtics"]=17;
m["Chicago Bulls"]=6;
m["Cleveland Cavaliers"]=1;
m["Dallas Mavericks"]=1;
m["Detroit Pistons"]=3;
m["Golden State Warriors"]=2;
m["Houston Rockets"]=2;
m["L.A. Lakers"]=11;
m["Miami Heat"]=3;
m["Milwaukee Bucks"]=1;
m["Minneapolis Lakers"]=5;
m["New York Knicks"]=2;
m["Philadelphia 76ers"]=2;
m["Philadelphia Warriors"]=2;
m["Portland Trail Blazers"]=1;
m["Rochester Royals"]=1;
m["San Antonio Spurs"]=5;
m["Seattle Sonics"]=1;
m["St. Louis Hawks"]=1;
m["Syracuse Nats"]=1;
m["Washington Bullets"]=1;
}
int main(){
//make();
solve();
int T;
scanf("%d\n",&T); // \n一定要加上清除缓冲区,不然 gets(c)会错误接收
int cas=1;
while(T--){
gets(c);
string s;
s=c;
printf("Case #%d: %d\n",cas++,m[s]);
}
return 0;
}