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;
}
目录
相关文章
|
XML 数据格式 测试技术
模拟摩天轮的效果
纯CSS3模拟摩天轮效果 .sunline{ position:relative; height: 400px; width: 400px; border: 2px solid transparent; border-radius: 50%; margin: 50px 0...
1008 0
|
索引
模拟社会关系
版权声明:您好,转载请留下本人博客的地址,谢谢 https://blog.csdn.net/hongbochen1223/article/details/46840015 本实例有求设计一个模拟社会关系的数据结构,每个人的信息用结构表示,包含名字,性别和指向父亲,母亲,配偶,子女的指针(设只限两个子女)。
814 0
new 的模拟实现
new 的模拟实现
82 0
|
3月前
|
前端开发 JavaScript
模拟 new 的实现
模拟 `new` 实现是指在 JavaScript 中,通过自定义函数来模拟内置的 `new` 操作符的行为,以便更好地理解其工作原理和对象构造过程。这种方式通常涉及创建一个新对象、绑定原型链、执行构造函数等步骤。
|
9月前
模拟队列训练
模拟队列训练
46 0
|
SQL 监控 前端开发
模拟数据在实际场景中的应用
模拟数据在实际场景中的应用
206 0
模拟数据在实际场景中的应用

热门文章

最新文章