-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixstringcase.cpp
More file actions
77 lines (59 loc) · 1.38 KB
/
Fixstringcase.cpp
File metadata and controls
77 lines (59 loc) · 1.38 KB
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
#include<iostream>
#include<algorithm>
#include<vector>
#include <array>
#include<cmath>
#include <string>
#include <iostream>
#include <string>
using namespace std;
string solve(const string& str)
{
string result;
int countup = 0;
int countlow = 0;
for (int i = 0; i < str.size(); i++)
{
if (str[i] >= 'A' && str[i] <= 'Z')
{
countup++;
}
if (str[i] >= 'a' && str[i] <= 'z')
{
countlow++;
}
}
if (countlow >= countup)
{
for (int i = 0; i < str.size(); i++)
{
result += tolower(str[i]);
}
}
else
{
for (int i = 0; i < str.size(); i++)
{
result += toupper(str[i]);
}
}
return result;
}
int main()
{
cout << solve("coDe");
return 0;
}
/*Description:
In this Kata, you will be given a string that may have mixed uppercase and lowercase letters and your task is to convert that string to either lowercase only or uppercase only based on:
make as few changes as possible.
if the string contains equal number of uppercase and lowercase letters, convert the string to lowercase.
For example:
solve("coDe") = "code". Lowercase characters > uppercase. Change only the "D" to lowercase.
solve("CODe") = "CODE". Uppercase characters > lowecase. Change only the "e" to uppercase.
solve("coDE") = "code". Upper == lowercase. Change all to lowercase.
More examples in test cases. Good luck!
Please also try:
Simple time difference
Simple remove duplicates
*/