[PAT解题报告] Broken Keyboard
简单题,给定两个字符串,问哪个键坏了。坏了的键,字母不会被打出来。数据保证合法。
所以我们可以直接比较,一个s,一个t,如果s和t对应字符不等,s的那个键一定坏了,注意这时t指针不动。
注意字母都转换为大写字母。
#include <cstdio> #include <cstring> #include <string> #include <cctype> using namespace std; bool mark[256]; char s[100],t[100]; int main() { scanf("%s%s",s,t); for (int i = 0, j = 0;s[i];++i) { char cs = toupper(s[i]); char ct = toupper(t[j]); if (s[i] == t[j]) { ++j; } else if (!mark[cs]) { mark[cs] = true; putchar(cs); } } puts(""); return 0; }
原题链接: http://www.patest.cn/contests/pat-a-practise/1084