hdu 1075 What Are You Talking About

#include <iostream>
#include <cstdio>
#include <string>
#include <map>

using namespace std;

int main()
{
    map<string, string>th;
    string a, b;
    string::size_type i, len;
    map<string, string>::iterator ite;

    getline(cin, a);
    th.clear();
    while(1){
        cin>>a;
        if(a!="END"){
            cin>>b;
            th[b] = a;
        }
        else break;
    }

    /*for(ite=th.begin(); ite!=th.end(); ite++)
        cout<<ite->first<<' '<<ite->second<<endl;*/

    getline(cin, a);
    getline(cin, a);
    while(1)
    {
        getline(cin, a);
        b.clear();
        if(a!="END")
        {
            len = a.size();
            for(i=0; i<len; i++)
            {
                if( isalpha(a[i]) )
                    b += a[i];
                else{
                    if( b.empty()!=true )
                    {
                        if( th.count(b)!=0 )
                            cout<<th[b]<<a[i];
                        else
                            cout<<b<<a[i];  //注意输出a[i];
                        b.clear();          //注意清空b
                    }
                    else
                        cout<<a[i];
                }
            }
            printf("\n");
        }
        else break;
    }
    return 0;
}

你可能感兴趣的:(hdu 1075 What Are You Talking About)