• poj 2503


    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
    ",buf);
    

      

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

      

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

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

    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
    ");
    		else
    			cout << outstr << endl;
    	}
    	return 0;
    }
    

      

     
  • 相关阅读:
    openfl使用64位的ndk时,编译报错的问题!
    Haxe是何物?
    jsp中如何判断el表达式中的BigDecimal==0
    如何在springmvc的请求过程中获得地址栏的请求
    【原创】【滑块验证码】
    【原创】【aes加密】
    【原创】【qrcodejs2】生成二维码
    【原创】【ueditor】监听内容
    【原创】【ueditor】内容过多时 菜单控件遮挡页面
    js杂谈
  • 原文地址:https://www.cnblogs.com/td15980891505/p/5699333.html
Copyright © 2020-2023  润新知