Description
给出了70年NBA总决赛的冠军名单,现给出一个人名,问其共得过几场冠军
Input
第一行一整数T表示用例组数,每组用例占一行输入一个长度不超过30的字符串表示人名(T<=30)
Output
对于每组用例吗,输出这个人得过几场冠军
Sample Input
2
Cleveland Cavaliers
Oklahoma City Thunder
Sample Output
Case #1: 1
Case #2: 0
Solution
水题,打个表就行了
Code
#include<cstdio>
#include<iostream>
#include<string>
#include<map>
using namespace std;
#define maxn 55
map<string,int>m;
map<string,int>::iterator it;
char c[maxn];
void init()
{
m.clear();
string s;
for(int i=0;i<70;i++)
{
gets(c);
s=c;
m[s]++;
}
for(it=m.begin();it!=m.end();it++)
cout<<"m[\""<<it->first<<"\"]="<<it->second<<";"<<endl;
}
void init2()
{
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()
{
init2();
int T,res=1;
scanf("%d\n",&T);
while(T--)
{
string s;
gets(c);
s=c;
printf("Case #%d: %d\n",res++,m[s]);
}
return 0;
}