码迷,mamicode.com
首页 > 其他好文 > 详细

poj 2503

时间:2016-07-23 19:39:28      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

Description

You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.

Input

Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.

Output

Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".

Sample Input

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

Sample Output

cat
eh
loops


灵活使用map容器和库函数sscanf.map容器使用:

1  插入数据 
  (1)   my_Map["a"]   =   1; 
  (2)   my_Map.insert(map<string,   int>::value_type("b",2)); 
  (3)   my_Map.insert(pair<string,int>("c",3)); 
  (4)   my_Map.insert(make_pair<string,int>("d",4)); 
  
 2   查找数据和修改数据 
  (1)   int   i   =   my_Map["a"]; 
            my_Map["a"]   =   i; 
  (2)   MY_MAP::iterator   my_Itr; 
            my_Itr.find("b"); 
            int   j   =   my_Itr->second; 
            my_Itr->second   =   j; 
  不过注意,键本身是不能被修改的,除非删除..

sscanf字符串处理函数的一般用法:

char buf[512];
sscanf("123456","%s",buf);//此处buf是数组名,它的意思是将123456以%s的形式存入buf中!
printf("%s\n",buf);

  

sscanf("123456","%4s",buf);    //意思是去字符串"123456"的最大长度为4的字符串存入buf中
printf("%s\n",buf);    //buf中的结果是1234

  


sscanf(str,"%s %s",buf1,buf2);
/*以上意思是将str通过空格分离为字符串buf1和buf2.
例如 str="hello word";
则分离后 buf11=‘hello‘ ,buf2=‘word‘ ;

gets函数一般用法:gets()函数用来从标准输入设备(键盘)读取字符串直到换行符结束,但换行符会被丢弃,然后在末尾添加‘\0‘字符。其调用格式为:

gets(s);可以读入空格,但是遇到回车结束,有点像getline(cin,str)类似。

//poj 2503,map容器经典用法
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
int main(){
	map<string, string> M;
	string s;
	char str[30], str1[12], str2[12];
	while (gets(str)){
		if (strlen(str) == 0)
			break;
		sscanf(str, "%s %s", str1, str2);
		M[string(str2)] = str1;
	}
	while (cin >> s){
		string outstr = M[s];
		if (outstr.size() == 0)
			printf("eh\n");
		else
			cout << outstr << endl;
	}
	return 0;
}

  

 

poj 2503

标签:

原文地址:http://www.cnblogs.com/td15980891505/p/5699333.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!