Hdoj 1075 What Are You Talking About 【MAP】

What Are You Talking About

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others)

Total Submission(s): 15322 Accepted Submission(s): 4922

Problem Description

Ignatius is so lucky that he met a Martian yesterday. But he didn’t know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book into English. Can you help him?

Input

The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string “START”, this string should be ignored, then some lines follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian’s language. A line with a single string “END” indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string “START”, this string should be ignored, then an article written in Martian’s language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new word into your translation, if you can’t find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(’ ‘), tab(‘\t’), enter(‘\n’) and all the punctuation should not be translated. A line with a single string “END” indicates the end of the book part, and that’s also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.

Output

In this problem, you have to output the translation of the history book.

Sample Input

START

from fiwo

hello difh

mars riwosf

earth fnnvk

like fiiwj

END

START

difh, i’m fiwo riwosf.

i fiiwj fnnvk!

END

Sample Output

hello, i’m from mars.

i like earth!

Hint

Huge input, scanf is recommended.

题意:给出一个字典,再给出一行字符串,如果字符串里面的单词在字典里,那么就输出对应的单词,反之直接输出。

用map映射一下就好了。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
const int M = 3e5;

char s[M];
map<string, string> m;

int main(){
    /*char a[15], b[15];
    scanf("%s", a);*/
   // ios::sync_with_stdio(false);
    string a, b;
    cin >> a;
    while(cin>>a, a != "END"){
            cin>>b;
        //scanf("%s", b);
        m[b] = a;
    }
    map<string, string>::iterator it = m.begin();
    /*for(; it != m.end(); ++ it){
            cout << it->first<<" "<<it->second<<endl;
        //printf("%s %s..\n", it->first, it->second);
    }*/
    cin>>a;
    //scanf("%s", a);
    getchar();
    while(gets(s), strcmp(s, "END")){
        int len = strlen(s);
        string temp;
        int i = 0, j = 0;
        while(i<len){
            if(s[i] >= ‘a‘&&s[i] <= ‘z‘){
                temp += s[i]; ++i;
            }
            else{
                //temp[j] = ‘\0‘;
                map<string, string>::iterator it = m.find(temp);
                if(it != m.end()){
                   cout << it->second;
                }
                else cout << temp;
                while(i < len&&(s[i]<‘a‘||s[i]>‘z‘)){
                    printf("%c", s[i]); ++i;
                }
                //j = 0;
                temp.clear();
            }
        }
        cout << endl;
    }
    return 0;
}
时间: 2024-07-28 13:58:10

Hdoj 1075 What Are You Talking About 【MAP】的相关文章

hdoj 1052 Tian Ji -- The Horse Racing【田忌赛马】 【贪心】

思路:先按从小到大排序, 然后从最快的開始比(如果i, j 是最慢的一端, flag1, flag2是最快的一端 ),田的最快的大于king的 则比較,如果等于然后推断,有三种情况: 一:大于则比較,二等于在推断田的最慢的是不是比king的最快的慢,三小于则与king的最快的比較: Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe

hdoj 5131 Song Jiang&#39;s rank list 【模拟】

Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 653    Accepted Submission(s): 323 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'

HDOJ 1142 A Walk Through the Forest 【Dijkstra】+【DFS】

题意:从2到1的所有路径中找出最短的路,并且输出最短路径有几条. 策略:先求出最短路径,然后再找出从2到1的最短路径有几条.最短路径用dijkstra算法来求出,什么是dijkstra算法,简单来说,dijkstra算法就是路径长度递增次序产生最短路径的算法: 基本思想是:把集合V分成两组: (1)S:已求出最短路径的顶点的集合 (2)V-S=T:尚未确定最短路径的顶点集合 将T中顶点按最短路径递增的次序加入到S中, 保证:(1)从源点V0到S中各顶点的最短路径长度都不大于 从V0到T中任何顶点

hdoj 1210 Eddy&#39;s 洗牌问题 【模拟】

题意:中文题,不翻译.. 策略:观察可知,第i张牌 如果小于等于n 那么他的序号就会变为i*2, 如果大于n 那么就会变成(i-n)*2-1  故 只需要模拟下就好了 AC by SWS 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1210 代码: #include<stdio.h> int main() { int n, cur, pre; while(scanf("%d", &n) == 1){ int ans

HDU 4941 Magical Forest 【离散化】【map】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点,每个点有一个数值,点的xy坐标是0~10^9,点存在于矩阵中.然后给出10^5个操作,1代表交换行,2代表交换列,3代表查询坐标为xy点的数值. 数据量很大........ 所以一直没有思路 后来赛后看了题解是先用离散化然后存在线性map里面. #include <iostream> #include <cstdio> #include <map

C++STL之关联容器【map】【set】

map以键-值対的形式组织,键的作用在于索引,而值表示所存储和读取数据. set仅包含一个键,并且有效的支持某个键是否存在的查询. 他们都是基于标准型类库pair实现,该类型在utility头文件中. 一:关于pair类型的操作 pair<T1,T2> p1; //创建一个空pair类型 pair<T1,T2> p1(v1,v2); //创建并初始化 make_pair(v1,v2) //生成pair对象 <,>,==,!=  //类型之间比较,遵循字典序,先比较fir

Hdoj 1466 计算直线的交点数 【DP】

计算直线的交点数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8630 Accepted Submission(s): 3885 Problem Description 平面上有n条直线,且无三线共点,问这些直线能有多少种不同交点数. 比如,如果n=2,则可能的交点数量为0(平行)或者1(不平行). Input 输入数据包含多个测试实例,

Hdoj 1428 A Walk Through the Forest 【spfa】+【记忆化搜索】

A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6397 Accepted Submission(s): 2348 Problem Description Jimmy experiences a lot of stress at work these days, especially sin

HDOJ A + B for you again 1867【KMP】

A + B for you again Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5114    Accepted Submission(s): 1286 Problem Description Generally speaking, there are a lot of problems about strings proces