UCF2016-g2g c u l8r(模拟)

简介: UCF2016-g2g c u l8r(模拟)

g2g c u l8r

时间限制: 1 Sec 内存限制: 128 MB

[提交] [状态]

题目描述

According to the national statistics, a teenager sends/receives 100+ text messages a day. Dr. Orooji’s teenage children are no exception but the problem is Dr. O (an old-fashioned, face-to-

face communicator) has difficulty reading text messages full of abbreviations (short-hands) sent to him by his children. Dr. O needs your help reading these text messages.

Given the list of abbreviations and a paragraph, you are to expand the text (paragraph) so that Dr. O can read it easily.

输入

The first input line contains an integer, n ( 1 ≤ n ≤ 20), indicating the number of abbreviations. These abbreviations are on the following n input lines, one per line. Each input line starts in column 1 and contains an abbreviation (1-5 characters, consisting of only lowercase letters and/or digits). The abbreviation is followed by exactly one space, and this is followed by the expanded version of the abbreviation (1-50 characters, consisting of only lowercase letters and spaces; assume the expanded version does not start or end with a space and contains no multiple consecutive spaces between words). Assume that all abbreviations are distinct, i.e., no duplicates.

The list of abbreviations is followed by a positive integer, p, indicating the number of input lines containing the paragraph to be expanded. The paragraph is on the following p input lines.

Assume these input lines do not exceed column 50, do not start or end with a space, and each line contains at least one word. The paragraph will contain only lowercase letters, digits, and spaces.

Assume that there will not be multiple consecutive spaces in the input paragraph.

A word is defined as a consecutive sequence of letters/digits. Assume that a word will be entirely on one input line, i.e., a word is not broken over two or more lines.

输出

Each line of the input paragraph must be on one line of output. The input line must be printed in the output exactly the same (spacing). The only exception is that each abbreviation must be replaced by its expanded version, i.e., when an abbreviation is found in the input, its expanded version must be output.

Note that an abbreviation must match a word completely and not just part of a word. For example, if u is an abbreviation for “you”, then u must appear as a word by itself in the paragraph in order to be replaced, i.e., if the abbreviation is part of a word in the paragraph (e.g., the paragraph contains the word buy or ugly or you), the u in these words should not be replaced.

样例输入 Copy

8

g2g got to go

g good

c see

l8 late

l8r later

d i am done

u you

r are

6

hi

how r u

you tell me

you are l8

d

c u l8r

样例输出 Copy

hi

how are you

you tell me

you are late

i am done

see you later


困扰了好久的代码突然找到bug了?

该死的getchar()

//#pragma GCC optimize(2)
//#include<bits/stdc++.h>
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
#define I_int ll
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
char F[200];
inline void out(I_int x) {
    if (x == 0) return (void) (putchar('0'));
    I_int tmp = x > 0 ? x : -x;
    if (x < 0) putchar('-');
    int cnt = 0;
    while (tmp > 0) {
        F[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while (cnt > 0) putchar(F[--cnt]);
    //cout<<" ";
}
int n,m;
map<string,string>mp;
void AC(){
    n=read();
    string a,b;
    while(n--){
        cin>>a;
        getchar();
        getline(cin,b);
        //cout<<a<<endl;
        //cout<<b<<endl;
        mp[a]=b;
       // cout<<mp[a]<<endl;
    }
    m=read();
  //  getchar();
    string s;
    while(m--){
        getline(cin,s);
        s+='\n';
        //cout<<s<<endl;
        int last=0;
        ///c u l8r
        ///0123456
        ///last=0,i=1 substr(last,i-last)
        ///last=
        string res;
        for(int i=0;i<s.size();i++){
            if(s[i]==' '||s[i]=='\n'){
                string tmp=s.substr(last,i-last);
                if(mp.count(tmp)) res+=mp[tmp];
                else res+=tmp;
                res+=s[i];
                last=i+1;
               // cout<<"%"<<i<<" "<<last<<endl;
            }
        }
        cout<<res;
    }
}
int main(){
    AC();
    return 0;
}
目录
相关文章
|
6月前
函数的模拟实现
函数的模拟实现
45 0
|
6月前
模拟队列训练
模拟队列训练
31 0
|
3月前
|
XML 传感器 算法
SFNC —— 模拟控制(五)
SFNC —— 模拟控制(五)
38 3
|
6月前
|
C语言
深入理解并模拟实现函数
深入理解并模拟实现函数
|
6月前
|
图形学 Python
物理光学:光的探索与编程模拟
物理光学:光的探索与编程模拟
64 0
|
6月前
函数的模拟实现1
函数的模拟实现1
52 0
|
Python
抽卡程序模拟
抽卡程序模拟
128 0
|
SQL 监控 前端开发
模拟数据在实际场景中的应用
模拟数据在实际场景中的应用
166 0
模拟数据在实际场景中的应用
new 的模拟实现
new 的模拟实现
70 0