-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblemnumber30.cpp
More file actions
39 lines (35 loc) · 801 Bytes
/
problemnumber30.cpp
File metadata and controls
39 lines (35 loc) · 801 Bytes
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
#include<iostream>
#include<algorithm>
#include<vector>
#include <string>
using namespace std;
//function Check what if a string has the same amount of 'x's and 'o's.
bool XO(string str)
{
transform(str.begin(), str.end(), str.begin(), ::tolower);
int result = 0;
for (int i = 0; i < str.size(); i++)
{
if (str[i] == 'x')
{
result++;
}
if (str[i] == 'o')
{
result--;
}
}
return !result;
}
int main() {
cout << XO("zzoo");
return 1;
}
/*Check to see if a string has the same amount of 'x's and 'o's. The method must return a boolean and be case insensitive. The string can contain any char.
Examples input/output:
XO("ooxx") => true
XO("xooxx") => false
XO("ooxXm") => true
XO("zpzpzpp") => true // when no 'x' and 'o' is present should return true
XO("zzoo") => false
*/