大意略。
思路:手写一个map容器即可。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
map<string, string> Map;
char str[60];
char temp1[30], temp2[30];
void init()
{
Map.clear();
}
void read_case()
{
init();
while(gets(str))
{
if(str[0] == '\0') break;
sscanf(str, "%s %s", temp1, temp2);
Map[temp2] = temp1;
}
}
void solve()
{
read_case();
while(gets(str))
{
if(Map.find(str) != Map.end()) cout<<Map[str]<<endl;
else cout<<"eh"<<endl;
}
}
int main()
{
solve();
system("pause");
}
本文介绍了一个简单的手写MAP容器实现方法,并提供了一个具体的C++实现案例。该案例使用了标准库中的map容器来模拟自定义映射,通过读取输入字符串并将其存储为键值对的方式进行操作。此外,还提供了查找功能,如果找到键则输出对应的值,否则输出默认提示。
133

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



