PAT1033.旧键盘打字

本文介绍了一个C++程序,该程序能够从输入的字符串中过滤掉已出现过的特定字符、数字及符号,只输出未出现过的字符。通过对输入字符的类型进行判断,并记录已出现的字符,实现了对后续输入字符串的有效过滤。
#include <iostream>
#include <string>
using namespace std;

int ch[26] = {};
int num[10] = {};
int other[4] = {};
int space = 0;
int main()
{
	string bro;
	getline(cin,bro);//注意第2个节点测试案例第一行为空行,如果不判断的话拿不到这1分
	if( bro.length() == 0 )
	{
		cin >> bro;
		cout<<bro;
		return 0;
	}
	for( int i = 0; i < bro.length(); ++i )
	{
		if ( bro[i] >= 'A' && bro[i] <= 'Z' )
		{
			int t = bro[i] - 'A';
			ch[t] = 1;
		}
		else if ( bro[i] >= '0' && bro[i] <= '9' )
		{
			int t = bro[i] - '0';
			num[t] = 1;
		}
		else if ( bro[i] >= '+' && bro[i] <= '.' )
		{
			int t = bro[i] - '0' + 5;
			other[t] = 1;
		}
		else if ( bro[i] == '_' )
		{
			space = 1;
		}
	}
	char test[100001];
	int j = 0;
	cin >> test;
	while ( test[j] != '\0' )
	{
		if ( test[j] >= 'A' && test[j] <= 'Z' && other[0] == 0 )
		{
			int t = test[j] - 'A';
			if ( ch[t] == 0 )
				cout<<test[j];
		}
		else if ( test[j] >= 'a' && test[j] <= 'z' )
		{
			int t = test[j] - 'a';
			if ( ch[t] == 0 )
				cout<<test[j];
		}
		else if ( test[j] >= '0' && test[j] <= '9' )
		{
			int t = test[j] - '0';
			if ( num[t] == 0 )
				cout<<test[j];
		}
		else if ( test[j] >= '+' && test[j] <= '.' )
		{
			int t = test[j] - '0' + 5;
			if ( other[t] == 0 )
				cout<< test[j];
		}
		else if ( test[j] == '_' && space == 0 )
		{
			cout<<test[j];
		}
		++j;
	}
	cout<<endl;
	return 0;
	
}




                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值