-
Notifications
You must be signed in to change notification settings - Fork 0
/
A1084.cpp
59 lines (49 loc) · 1.24 KB
/
A1084.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <cstdio>
#pragma warning(disable: 4996)
#define MAXSIZE 80
using namespace std;
struct has_t {//hash
bool has;//hash
bool dis;//display
}has[63] = { 0 };
int hash_table(char cha) {
if (cha >= 'A' && cha <= 'Z') return cha - 'A';
else if (cha >= 'a' && cha <= 'z') return cha - 'a' + 26;
else if (cha >= '0' && cha <= '9') return cha - '0' + 52;
else return 62;
}
int main() {
char ori[MAXSIZE] = { 0 }, typ[MAXSIZE] = { 0 };//original; typed-out
//1. INPUT: storage two string
scanf("%s%s", ori, typ);
//2. EXECUTE: the broken string translate to hash value
char* s = typ;
int idx = 0;
while (*s) {
idx = hash_table(*s);
has[idx].has = true;
s++;
}
//3. OUTPUT: traversal the original string
s = ori;
char tmp;
while (*s) {
idx = hash_table(*s);
if (!has[idx].has && !has[idx].dis) {
if ((*s >= 'A' && *s <= 'Z')
|| (*s >= 'a' && *s <= 'z')) {
tmp = *s ^ 32;// translate to CAP or low
if (!has[idx].dis && !has[hash_table(tmp)].dis) {
has[idx].dis = true;
has[hash_table(tmp)].dis = true;
printf("%c", *s & 223);// always CAP;
}
} else {
has[idx].dis = true;
printf("%c", *s);
}
}
s++;
}
return 0;
}