-
Notifications
You must be signed in to change notification settings - Fork 10
/
Day-263.cpp
97 lines (96 loc) · 2.61 KB
/
Day-263.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
// i can't represent last terminal_character on my terminal
#include <iostream>
#include <functional>
#include <set>
using namespace std;
set<char> terminal {'.', '?', '!'};
set<char> seperator {',', ';', ':'};
bool valid(string &s, int index = 0) {// checking until first terminal character appears
// (This is a Valid string. Here, it is again!)
// first word needs to be a title
if(index == s.size()) {
return true;
}
if(!isupper(s[index])) {
return false;
}
++index;
while (index < (int)s.size() && s[index]!=' ') {
if (isupper(s[index])) {
return false;
}
if(terminal.find(s[index]) != terminal.end()) {
if (index-1<0 || (!isalpha(s[index-1]))){
return false;
}
if(index+1 < s.size()) {
if (s[index+1] != ' ') {
return false;
}
} else {
return true;
}
return valid(s , index+2);
}
if(seperator.find(s[index]) != seperator.end()) {
if (index-1<0 || (!isalpha(s[index-1]))){
return false;
}
if (index+1 < s.size() && s[index+1]!=' ') {
return false;
}else if (index +1 == s.size()) {
return false;
}
}
++index;
}
++index;
while (index < (int)s.size()) {
if (terminal.find(s[index]) != terminal.end()) {
if (index-1<0 || (!isalpha(s[index-1]))){
return false;
}
if(index+1 < s.size()) {
if (s[index+1] != ' ') {
return false;
}
} else {
return true;
}
return valid(s , index+2);
}
if(seperator.find(s[index]) != seperator.end()) {
if (index-1<0 || (!isalpha(s[index-1]))){
return false;
}
if (index+1 < s.size() && s[index+1]!=' ') {
return false;
}else if (index +1 == s.size()) {
return false;
}
}
int counter{};
while (index<s.size() && s[index]==' ') {
++counter;
++index;
}
if(counter >=2 ) {
return false;
}
if (isupper(s[index])){
return false;
}
index++;
}
return true;
}
int main(void){
string s;
getline(cin,s);
if (valid(s)) {
cout << "Valid" << '\n';
} else {
cout << "Invalid" << '\n';
}
return 0;
}