PAT 甲級(jí) 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:

易錯(cuò)點(diǎn):忽視給定條件-- 不區(qū)分大小寫


示例:

#include <iostream>

#include <string>

using namespace std;

string str1,str2;

void switchToCapital(string &str)

{

? ? for(int i=0;i<str.size();++i)

? ? {

? ? ? ? if(isalpha(str[i])&&str[i]>='a')

? ? ? ? str[i]=str[i]+'A'-'a';

? ? }

}

void test02()

{

? ? getline(cin,str1);

? ? getline(cin,str2);

? ? switchToCapital(str1);

? ? switchToCapital(str2);

? ? string str3;

? ? for(int i=0;i<str1.size();++i)

? ? {

? ? ? ? int pos=str2.find(str1[i]);

? ? ? ? if(pos<0)

? ? ? ? ? {

? ? ? ? ? ? int pos2=str3.find(str1[i]);

? ? ? ? ? ? ? if(pos2<0)

? ? ? ? ? ? ? str3+=str1[i];

? ? ? ? ? }

? ? }

? ? cout<<str3<<endl;

}

int main()

{

? ? test02();

? ? return 0;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容