对字符串进行编号
代码:
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<vector>
using namespace std;
int main()
{
char ch[20],str[20];
int T,n,m,i,j;
scanf("%d",&T);
while(T--)
{
map<string,int>mp;//字符串变为整型
mp.clear();//清空
int t=1;
scanf("%d",&n);
while(n--)
{
memset(ch,'\0',sizeof(ch));
scanf("%s",ch);
mp[ch]=t++;//将字符串ch 标记为 t
}
memset(ch,'\0',sizeof(ch));
while(scanf("%s",str)!=EOF)
{
printf("%d\n",mp[str]);//输出字符串对应的编号
memset(ch,'\0',sizeof(ch));
}
}
return 0;
}