map水题= =
我发现我有点太依赖map了。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
map<string,string> mp;
int main()
{
int n;
char str[50],s1[20],s2[20];
mp.clear();
while (1)
{
gets(str);
if (strcmp(str,"") == 0)
break;
sscanf(str,"%s%s",s1,s2);
mp[s2]=s1;
}
while (scanf("%s",str) != EOF)
{
if (mp.find(str) != mp.end())
{
printf("%s\n",mp[str].c_str());
}
else
printf("eh\n");
}
}
本文介绍了一个简单的程序,该程序利用C++中的map容器来存储字符串映射关系,并根据输入查找对应的值。通过读取文件并将特定字符串作为键值对存储在map中,当程序接收到查询时能够返回相应的结果。
847

被折叠的 条评论
为什么被折叠?



