杭电 acm 1075 What Are You Talking About

这是一个使用C++编写的程序,用于处理杭电ACM比赛中的问题1075。程序通过读取输入的字符串映射关系,然后对新的字符串进行处理,遇到已知的关键词则用其对应的值替换,否则保持原样输出。注意,程序中使用了getline和getchar函数来处理输入中的空白字符和换行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
#include <map>
#include <string>
#include <cctype>
#include <cstdio>
using namespace std;

typedef map<string,string> Mss;


Mss mss;
int main()
{
    string s;
    cin>>s;
    while(1)
    {
        cin>>s;
        if(s==string("END"))break;

        string key;
        cin>>key;
        mss[key]=s;
    }

    cin>>s;
    getchar();
    /*
     * you may ask what getchar() does here
     * cin ignores tab('\t') enter('\n') space(' '),
     * ignoring doesn't mean discarding,the char '\n' is still in the buffer
     */
    while(1)
    {
        getline(cin,s);
        if(s==string("END"))break;
        string key;
        size_t i=0;
        for(;i<s.size();++i)
        {
            if(isalpha(s[i]))
            {
                key.push_back(s[i]);
            }
            else 
            {
                if(!key.empty())
                {
                    Mss::iterator it=mss.find(key);
                    if(it==mss.end())cout<<key;
                    else cout<<it->second;
                }
                key.clear();
                cout<<s[i];
            }
        }
        cout<<endl;

    }
    return 0;
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值