-
Notifications
You must be signed in to change notification settings - Fork 1
/
oblig2.cpp
123 lines (97 loc) · 2.19 KB
/
oblig2.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <iostream>
#include <cstring>
const int LEN = 15;
int len;
char * txt;
bool isVowel(char a);
bool check(char a[]);
void swap(char & x, char & y);
void rotateLeft(char a[], int i);
void perm(int i);
void display(char a[]);
int main() {
char temp[LEN];
std::cin.getline(temp, LEN);
len = strlen(temp);
txt = new char[len];
strcpy(txt, temp);
for (int i = 0; i < len; i++) {
std::cout << isVowel(txt[i]) << std::endl;
}
perm(0);
std::cout << '\n';
display(txt);
std::cout << "\n\n";
return 0;
}
//true if a is a vowel, elseway false
bool isVowel(char a) {
a = toupper(a);
char vowels[] = "AEIOU";
for (int i = 0; i < 5; i++) {
if (a == vowels[i]) {
return true;
}
}
return false;
}
//checks a set of rules set by the task description
bool check(char a[]) {
for (int i = 2; i < len; i++) {
if (a[i] == a[i - 1] && isVowel(a[i]) && isVowel(a[i - 1])) {
return false;
}
}
for (int i = 3; i < len; i++) {
if (isVowel(a[i]) && isVowel(a[i - 1]) && isVowel(a[i - 2])) {
return false;
}
if (a[i] == a[i - 1] == a[i - 2] && !isVowel(a[i]) &&
!isVowel(a[i - 1]) && !isVowel(a[i - 2])) {
return false;
}
}
for (int i = 4; i < len; i++) {
if (!isVowel(a[i]) && !isVowel(a[i - 1]) && !isVowel(a[i - 2])
&& !isVowel(a[i - 3])) {
return false;
}
}
if (a[1] == a[2]) {
return false;
}
return true;
}
void swap(char & x, char & y) {
char temp = x;
x = y;
y = temp;
}
void rotateLeft(char a[], int i) {
int k;
char x = a[i];
for (k = i + 1; k < len; k++)
a[k - 1] = a[k];
a[len - 1] = x;
}
void perm(int i) {
int t;
if (i == len - 1 && check(txt))
display(txt);
else {
perm(i + 1);
for (t = i + 1; t < len; t++) {
swap(txt[i], txt[t]);
perm(i + 1);
}
rotateLeft(txt, i);
}
}
void display(char a[]) {
std::cout << "\n";
for (int i = 0; i < len; i++)
std::cout << a[i] << ' ';
}