-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleSymbols
47 lines (34 loc) · 1.07 KB
/
SimpleSymbols
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
/*Challenge
Have the function SimpleSymbols(str) take the str parameter being passed and determine if it is
an acceptable sequence by either returning the string true or false.
The str parameter will be composed of + and = symbols with several letters between
them (ie. ++d+===+c++==a) and for the string to be true each letter must be surrounded by a + symbol.
So the string to the left would be false. The string will not be empty and will have at least one letter.
Sample Test Cases
Input:"+d+=3=+s+"
Output:"true"
Input:"f++d+"
Output:"false"*/
#include <iostream>
#include <string>
using namespace std;
bool isLetter(char c) {
if (c > 96 && c < 123 || c > 64 && c < 91)
return true;
return false;
}
string SimpleSymbols(string str) {
int len = str.length() - 1;
if (isLetter(str[0]) || isLetter(str[len]))
return "false";
for (int i = 1; i < str.length() - 1; i++)
if (isLetter(str[i]) && (str[i - 1] != '+' || str[i + 1] != '+'))
return "false";
return "true";
}
void main() {
string str;
getline(cin, str);
cout << SimpleSymbols(str);
system("pause>0");
}