Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

map<char*,char*> 问题 求助

Posted by July at 2007-12-20 17:29:40 on Problem 2503 and last updated at 2007-12-20 17:31:57
请教:
  我用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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator