1084. Broken Keyboard (20)

本文通过一个C++程序实例展示了如何使用标准库中的队列进行字符输入的接收与对比操作,并实现特定条件下的字符输出。该程序首先从标准输入读取两组字符到不同的队列中,然后逐个比较队列中的字符,对于不匹配的字符,如果满足特定条件则输出。

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

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>

#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <queue>

using namespace std;



int book[1000]={0};

int main()
{
  //  freopen("in.txt","r",stdin);

    queue<char> q1,q2;
    char ch;
    while( (ch=getchar())!='\n' )
        q1.push(ch);
    while( (ch=getchar())!=EOF )
    {
        if(ch=='\n')//吸收掉最后一个回车键,虽然不加对此题也没有影响,但是最好加上
            break;
        q2.push(ch);
    }


    while(!q1.empty())
    {
        if(q1.front()!=q2.front())
        {
            int t=q1.front();
            if(q1.front()>='a' && q1.front()<='z')
                t=t-32;
            if(book[t]==0)
            {
                printf("%c",t);
                book[t]++;
            }

            q1.pop();
        }
        else
        {
            q1.pop();
            q2.pop();
        }
    }




    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值