1084 Broken Keyboard (20分)【字符串处理】

 1084 Broken Keyboard (20分)

On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.

Now given a string that you are supposed to type, and the string that you actually type out, please list those keys which are for sure worn out.

Input Specification:

Each input file contains one test case. For each case, the 1st line contains the original string, and the 2nd line contains the typed-out string. Each string contains no more than 80 characters which are either English letters [A-Z] (case insensitive), digital numbers [0-9], or _ (representing the space). It is guaranteed that both strings are non-empty.

Output Specification:

For each test case, print in one line the keys that are worn out, in the order of being detected. The English letters must be capitalized. Each worn out key must be printed once only. It is guaranteed that there is at least one worn out key.

Sample Input:

7_This_is_a_test
_hs_s_a_es

Sample Output:

7TI

解题思路:

这道题目使用c++的STL库的话会非常简单:

1.首先用两个string类型变量a和b,存储应该输入文字以及实际输入文字。 

2.枚举第一个字符串中的字符,对当前枚举字符c1,枚举第二个字符串中的字符(设为c2),如果c1和c2像等则说明c1字符按键没坏,然后继续枚举下一个c1和c2;否则,说明当前c1按键已坏,将当前已坏的字符加入res字符串中(如果已存在不加入,否则对于字母转换为大写后加入),然后枚举下一个c1。

#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;

int main()
{
	string res = "";
	string a, b;
	cin >> a >> b;
	int pos = 0;
	for (int i = 0; i < a.length(); i++)
	{ 
		if (a[i] == b[pos])    //没坏
			pos++; 
		else                         //否则坏了
		{ 
			if (!isalpha(a[i]) && res.find(a[i]) == res.npos)   //判断res中是否存在该字符
				res += a[i];
			else
			{
				if (res.find(toupper(a[i])) == res.npos)
					res += toupper(a[i]);
			}
		}
	}
	cout << res << endl;
	return 0;
}

 

根据引用\[1\]中的堆栈信息,出现了一个异常:org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe。这个异常是在OutputBuffer :: realWriteBytes方法中抛出的。根据注释,这个IOException几乎总是由于远程客户端中止请求而导致的\[3\]。所以,这个异常通常是由于客户端中止请求导致的。在引用\[2\]中的代码中,我们可以看到在下载文件时,如果客户端中止请求,就会抛出异常并打印出错信息。所以,这个异常可能是由于下载文件时客户端中止请求导致的。 #### 引用[.reference_title] - *1* *3* [org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe问题探究](https://blog.csdn.net/lingyejun/article/details/127336601)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [下载文件出现异常:org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe](https://blog.csdn.net/weixin_43726137/article/details/129104575)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

胡小涛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值