-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
91 lines (77 loc) · 1.92 KB
/
main.c
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
#include "header.h"
void gendata(char* CharArrayOfLength, int N);
int main()
{
clock_t start1, end1, start2, end2, start3, end3, start4, end4;
char *vector, *rotate;
int length, rot, G = 0;
int plusminus = 0;
printf("Enter the String distance and Rotate distance : ");
scanf_s("%d %d", &length, &rot);
G = gcd(length, rot);
vector = (char *)malloc(sizeof(char)*(length * 2));
rotate = (char *)malloc(sizeof(char)*(length * 2));
gendata(vector, length);
printf("랜덤으로 받은 문자열 : %s\n",vector);
strcpy(rotate, vector);
start1 = clock();
trivial(rotate, length, rot);
end1 = clock();
printf("\nTrivial Solution : %s", rotate);
if (rot < 0)
{
rot = abs(rot);
plusminus = 1;
}
strcpy(rotate, vector);
if (plusminus == 0)
{
start2 = clock();
Rev(length, rot, rotate);
}
else if (plusminus == 1)
{
start2 = clock();
Rev(length, length - rot, rotate);
}
end2 = clock();
printf("\nReverse : %s", rotate);
strcpy(rotate, vector);
if (plusminus == 0)
{
start3 = clock();
jug(rot, length, rotate, G);
}
else if (plusminus ==1)
{
start3 = clock();
mjug(rot, length, rotate, G);
}
end3 = clock();
printf("\nJuggling : %s", rotate);
strcpy(rotate, vector);
if (plusminus == 0)
{
start4 = clock();
BS(length, rot, rotate);
}
else if (plusminus == 1)
{
start4 = clock();
mBS(length, rot, rotate);
}
end4 = clock();
printf("\nBlock - Swap : %s\n", rotate);
printf("\nTrivial Solution Running Time : %fms", (double)(end1 - start1));
printf("\nReverse Running Time : %fms", (double)(end2 - start2));
printf("\nJugging Running Time : %fms", (double)(end3 - start3));
printf("\nBlock - Swap Running Time : %fms\n", (double)(end4 - start4));
return 0;
}
void gendata(char* CharArrayOfLength, int N)
{
srand(time(NULL));
for (int i = 0; i < N; i++)
CharArrayOfLength[i] = (rand() % 26 + 'A');
CharArrayOfLength[N] = NULL;
}