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.
输入描述:
输出描述:
输入例子:
输出例子:
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;
}
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++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++编写简单的打靶游戏
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C与C++之间相互调用实例方法讲解
- C++中拷贝构造函数的应用详解
- C++中引用(&)的用法与应用实例分析
- C++使用CriticalSection实现线程同步实例
- C++智能指针实例详解
- 解析C++ 浮点数的格式化输出