您的位置:首页 > 编程语言 > C语言/C++

Broken Keyboard

2015-05-28 22:43 513 查看
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. 

输入描述:

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.



输出描述:

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.



输入例子:

7_This_is_a_test

_hs_s_a_es



输出例子:


7TI

#include <iostream>
#include <string>
#include <algorithm>

bool charEqualIgnorecase(const char &ch1, const char &ch2);
int main()
{
std::string firstStr;
std::string secondStr;
std::cin >> firstStr;
std::cin >> secondStr;
size_t i = 0;
size_t j = 0;
std::string outputStr = "";
bool isExists = false;
while (i != firstStr.size())
{
if (firstStr[i] != secondStr[j])
{

for (size_t outI = 0; outI != outputStr.size();outI++)
{
if (charEqualIgnorecase(outputStr[outI], firstStr[i]))
{
isExists = true;
break;
}
}
if (!isExists)
{
outputStr += firstStr[i];
}
i++;
isExists = false;
}
else
{
++i;
++j;
}
}
transform(outputStr.begin(), outputStr.end(), outputStr.begin(), toupper);

std::cout << outputStr << std::endl;
return 0;
}

bool charEqualIgnorecase(const char &ch1, const char &ch2)
{
if (ch1 == ch2)
{
return true;
}
else if ((ch1 > 90 ? ch1 - 32 : ch1) == ch2)
{
return true;
}
else if ((ch2 > 90 ? ch2 - 32 : ch2) == ch1)
{
return true;
}
else
return false;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++