-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain3.cpp
More file actions
70 lines (70 loc) · 1.09 KB
/
Copy pathmain3.cpp
File metadata and controls
70 lines (70 loc) · 1.09 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *move(char *s, int n, int step);
int main()
{
int n, m, i, j, k, p, q;
char s1[20], s2[20], s3[20], s4[20], s5[20][20], c;
scanf("%d", &n);
scanf("%d", &m);
getchar();
gets(s1);
gets(s2);
for(i = 0;i < m;i++)
{
scanf("%c", &c);
scanf("%d", &p);
scanf("%d", &q);
getchar();
gets(s3);
j = 0;
strcpy(s4, move(s2, n, p));
while(s3[j] != '\0')
{
if(c == 'E')
{
for(k = 0;k < n;k++)
{
if(s3[j] == s1[k])
{
s5[i][j] = s4[k];
break;
}
}
}
else
{
for(k = 0;k < n;k++)
{
if(s3[j] == s4[k])
{
s5[i][j] = s1[k];
break;
}
}
}
strcpy(s4, move(s4, n, q));
j++;
}
s5[i][j] = '\0';
}
for(i = 0;i < m;i++)
{
printf("%s\n", s5[i]);
}
return 0;
}
char *move(char *s, int n, int step)
{
int len, i;
len = strlen(s);
char *s1;
s1 = (char *)malloc((len + 1) * sizeof(char));
for(i = 0;i < n;i++)
{
s1[i] = s[(i + step) % n];
}
s1[i] = '\0';
return s1;
}