-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathZOJ1244(AC).cpp
99 lines (87 loc) · 1.24 KB
/
ZOJ1244(AC).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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
void sort(char a[], int n)
{
int i, j;
char tmp;
for(i = 0; i < n - 1; i++){
for(j = i + 1; j < n; j++){
if(a[i] > a[j]){
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
}
}
int find(char a[], int n, int key)
{
int i;
for(i = 0; i < n; i++){
if(a[i] == key){
return i;
}
}
return -1;
}
int main()
{
int i;
int j;
int n;
int c;
int pos;
char str[1000];
char a[100];
char dst;
char src;
int casecount;
casecount = 0;
while(true){
c = 0;
a[c] = 'a';
c++;
gets(str);
sscanf(str, "%d", &n);
if(n == 0){
break;
}else{
casecount++;
}
for(i = 0; i < n; i++){
gets(str);
sscanf(str, "%c = %c", &dst, &src);
pos = find(a, c, src);
if(pos != -1){
pos = find(a, c, dst);
if(pos == -1){
a[c] = dst;
c++;
}
}else{
pos = find(a, c, dst);
if(pos != -1){
for(j = pos + 1; j < c; j++){
a[j - 1] = a[j];
}
c--;
}
}
}
sort(a, c);
printf("Program #%d\n", casecount);
if(c == 0){
printf("none");
printf("\n\n");
}else{
for(i = 0; i < c; i++){
printf("%c ", a[i]);
}
printf("\n\n");
}
}
return 0;
}