Skip to content

Commit b74197d

Browse files
authored
Merge pull request liuchuo#25 from xiaorong61/patch-2
Update 1033. 旧键盘打字(20).cpp
2 parents e9ac2b6 + 387b66c commit b74197d

File tree

1 file changed

+11
-48
lines changed

1 file changed

+11
-48
lines changed

PAT乙级(Basic Level)/1033. 旧键盘打字(20).cpp

+11-48
Original file line numberDiff line numberDiff line change
@@ -32,54 +32,17 @@ _hs_s_a_tst
3232
如果没有一个字符能被打出,则输出空行。
3333
重要的事情要说三遍!!
3434

35+
#include <cctype>
3536
#include <iostream>
3637
using namespace std;
3738
int main() {
38-
string a, b;
39-
getline(cin, a);//为了防止第一行是空的,不能用cin >> a,用getline(cin, a)
40-
getline(cin, b);
41-
if (a.length() == 0) {
42-
cout << b;
43-
return 0;
44-
}
45-
int flag = 0;
46-
int lena = a.length();
47-
int lenb = b.length();
48-
//检验是否有大写
49-
for (int i = 0; i < lena; i++) {
50-
if (a[i] == '+') {
51-
flag = 1;
52-
a[i] = '#';
53-
}
54-
}
55-
//去除大写字母
56-
if(flag) {
57-
for (int i = 0; i < lenb; i++) {
58-
if (b[i] >= 'A' && b[i] <= 'Z') {
59-
b[i] = '#';
60-
}
61-
}
62-
}
63-
//去除其它字母
64-
for (int i = 0; i < lenb; i++) {
65-
for (int j = 0; j < lena; j++) {
66-
if (a[j] == b[i]) {
67-
b[i] = '#';
68-
}
69-
if (a[j] >= 'A' && a[j] <= 'Z' && b[i] == a[j] + 32) {
70-
b[i] = '#';
71-
}
72-
}
73-
}
74-
int flag1 = 0;
75-
//print
76-
for (int i = 0; i < lenb; i++) {
77-
if (b[i] != '#') {
78-
cout << b[i];
79-
flag1 = 1;
80-
}
81-
}
82-
if (flag1 == 0)
83-
cout << endl;
84-
return 0;
85-
}
39+
string bad, should;
40+
getline(cin, bad); //为了防止第一行是空的,不能用cin >> ,用getline(cin, ...)
41+
getline(cin, should);
42+
for (int i = 0, length = should.length(); i < length; i++) {
43+
if (bad.find(toupper(should[i])) != string::npos) continue;
44+
if (isupper(should[i]) && bad.find('+') != string::npos) continue;
45+
cout << should[i];
46+
}
47+
return 0;
48+
}

0 commit comments

Comments
 (0)