您的位置:首页 > 其它

1084. Broken Keyboard (20)

2015-08-01 14:15 375 查看

1084. Broken Keyboard (20)

时间限制200 ms 内存限制65536 kB 代码长度限制16000 B 判题程序Standard作者CHEN, Yue 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
在typeOut长度范围内 original和打出的typeOut一样 两者都加, 否则typeOut缺失看看这个缺失的在不再brokenkeys里面,不在加;在typeOut长度范围外 看看剩下的original是否有不在brokenkeys里面的,不在加

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户
8月01日 14:07答案正确201084C++ (g++ 4.7.2)1436datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分
0答案正确138412/12
1答案正确14363/3
2答案正确13041/1
3答案正确13041/1
4答案正确13083/3

#include<iostream>   
#include<string>
using namespace std; 
bool TheSame(char A, char B)
{
  if (A == B || A >= 'a'&&A <= 'z'&&A - 'a' + 'A' == B)
    return true;
  return false;
}
char AddTheBag(char c)
{
  if (c >= 'a'&&c <= 'z')return c - 'a' + 'A';
  return c;
}
bool NoInbrokeys(string brokenkeys, char ctemp,int lenb)
{
  int  index;
  for (index = 0; index < lenb; index++)
  {
    if (brokenkeys[index] == ctemp || ctemp >= 'a'&&ctemp <= 'z'&&ctemp - 'a' + 'A' == brokenkeys[index])
      return false;
  }
  return true;
}
int main()
{     
  string original, brokenkeys,typeOut;
  int oindex, tindex, leno,lent,lenb;
  cin >> original >> typeOut;
  leno = original.size();
  lent = typeOut.size();
  lenb = brokenkeys.size();
  for (oindex = 0,tindex=0; oindex < leno; oindex++)
  {
    if (tindex < lent)
    {
      if (TheSame(original[oindex], typeOut[tindex]))
      {
        tindex++;
      }
      else if (NoInbrokeys(brokenkeys, original[oindex], lenb))
      {
        brokenkeys += AddTheBag(original[oindex]);
        lenb++;
      }
    }
    else  if (NoInbrokeys(brokenkeys, original[oindex], lenb))
    {
      brokenkeys += AddTheBag(original[oindex]);
      lenb++;
    } 
  }
  cout << brokenkeys << endl;
  system("pause");   
  return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: