-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_subset.cpp
More file actions
65 lines (54 loc) · 1.22 KB
/
password_subset.cpp
File metadata and controls
65 lines (54 loc) · 1.22 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
// my first program in c++
#include <iostream>
#include <stdint.h>
using namespace std;
uint8_t solution(string &S);
int main(void)
{
/** Here we declare the string, although
* This could also be an input from the user.
*/
string str = "laskjflkGkslGa0fa1adHj5";
solution(str);
return 0;
}
uint8_t solution(string &S)
{
// write your code in C++14 (g++ 6.2.0)
static uint16_t n = 0;
static uint16_t current_max_subset = 0;
static uint16_t largest_max_subset_found = 0;
bool uppercase_in_subset = false;
while(S.length() >= n)
{
if(isupper(S[n]))
{
current_max_subset += 1;
if(!uppercase_in_subset)
{
uppercase_in_subset = true;
}
}
// check if char is lower case
if(islower(S[n]))
{
current_max_subset += 1;
}
if(!(isupper(S[n])) && !(islower(S[n])))
{
if (largest_max_subset_found < current_max_subset)
{
if(uppercase_in_subset)
{
largest_max_subset_found = current_max_subset;
}
// reset uppercase flag
uppercase_in_subset = false;
current_max_subset = 0;
}
}
//increase counter
++n;
}
cout << largest_max_subset_found;
}