B1033(20)

本文探讨了在PAT竞赛中使用cin.getline()替代gets()进行字符串输入的方法,解决了因输入格式不确定性导致的问题。文章通过示例代码详细解释了如何根据不同输入情况调整读取策略,并对比了cin.getline()与scanf()在特定场景下的应用。

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

该来的总会来的,gets在pat中无法进行编译,我们可以采用cin.getline,因为题目要求的是第二个肯定有输入,隐含了第一个可能没输入的情况,所以用scanf没办法接收这种情况,测试点3不通过,本题还有一个要求,即最大的几个字符没有要求,可能会导致越界

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn=100010;
int main()
{
	char str1[maxn];
	char str2[maxn];
	cin.getline(str1, maxn);
	scanf("%s",str2);
	bool hashchar[128]={false};
	bool ma=false;
	int len1=strlen(str1);
	int len2=strlen(str2);
	for (int i=0;i<len1;i++)
	{
	   hashchar[str1[i]]=true;
	   if(str1[i]=='+')
	   ma=true;
	}
	for (int i=0;i<len2;i++)
	{
		char now=str2[i];
		if(str2[i]>='A'&&str2[i]<='Z'&&ma==true)
		continue;
		if (str2[i]>='a'&&str2[i]<='z')
		str2[i]-=32;
		if (hashchar[str2[i]]==false)
		printf("%c",now);
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值