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;
    }
    
    
  • 相关阅读:
    html上传图片后,在页面显示上传的图片
    arcgis 将日期字段赋值为当前日期
    一些使用文件夹重定向的系统中,运行ArcToolbox中的GP工具报IE脚本错误
    Gps中的 gpx文件和excel文件互相转换方法
    ARCMAP 本文将描述如何利用识别工具显示一幅与要素相关的图片。
    arcgis 正确显示标注的大小写
    在一些系统中,运行ArcToolbox中的任何GP工具报Microsoft脚本错误,并且工具对话框显示为空白
    arcgis Howto: 用空格作为分隔符提取字符串中的字符并赋值到另一个新字段
    使用.Net开发ArcGIS9扩展组件的注册到ArcMAP中
    arcgis 利用DEM寻找最小阻力路径 来自http://support.esrichinabj.cn/2008/0325/1189.html
  • 原文地址:https://www.cnblogs.com/OvOq/p/14853155.html
Copyright © 2011-2022 走看看