OpenJudge2804

map应用不熟悉,还有就是, 我发觉map运行总是很久

 

#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <map>

using namespace std; 

char s1[11], s2[11]; 

int main()
{
	ifstream in("OpenJudgeText.txt"); 

	int i, j, len=0;;
	char c, s[22]; 
	map<string, string> m; 
	string str1, str2; 
	do
	{
		gets(s);
		if(strcmp(s, "\0")==0)
			break; 
		for(i=0; s[i]!=' '; i++)
			s1[i] = s[i];
		s1[i++] = '\0'; 

		for(j=0; s[i]!='\0'; i++, j++)
			s2[j] = s[i];
		s2[j] = '\0';

		str1 = s1; 
		str2 = s2; 
		m[str2] = str1; 
	}while(true); 

	while(true)
	{
		memset(s2, 0, sizeof s2);
		gets(s2);
		if(strcmp(s2, "\0")==0)
			break; 
		str2 = s2;
		if(m.count(str2))
			cout<<m[str2]<<endl; 
		else 
			cout<<"eh"<<endl; 
	}
//	cin>>i; 

	return 0; 
}


 

你可能感兴趣的:(c,String)