zoukankan      html  css  js  c++  java
  • 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+='
    ';
            //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]=='
    '){
                    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;
    }
    
    
  • 相关阅读:
    手搓一个兔子问题(分享一个C语言问题,持续更新...)
    一个C语言萌新的学习之旅(持续更新中...)
    ...续上文(一个小萌新的C语言之旅)
    手搓一个C语言简单计算器。
    嘿,C语言(持续更新中...)
    一个博客萌新的博客之旅。。。。
    vue+uikit3+laravel快速建站
    mpvue开发博客园小程序
    C语言俄罗斯方块小游戏练习
    c语言贪吃蛇小游戏练习
  • 原文地址:https://www.cnblogs.com/OvOq/p/14853155.html
Copyright © 2011-2022 走看看