| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
map<char*,char*> 问题 求助请教:
我用map<char*,char*>存储单词,但是在insert的时候总是出现覆盖的情况,无论插入多少,只剩下最后一条插入的数据,不知道为何?
下面是程序:
#include<cstdio>
#include<map>
using namespace std;
map<char *,char *> dict;
map<char *,char *>::iterator it;
char line[100];
char before[15],end[15];
int p=0;
int main()
{
while(gets(line) && line[0])
{
char *br=strchr(line,' ');
*br=0;
strcpy(end,br+1);
strcpy(before,line);
dict.insert(make_pair(end,before));
}
for(it=dict.begin();it!=dict.end();it++)
{
puts(it->first);
puts(it->second);
}
while(scanf("%s",line)!=EOF)
if((it=dict.find(line))!=dict.end())
printf("%s\n",it->second);
else
puts("eh");
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator