-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.cpp
107 lines (86 loc) · 1.84 KB
/
Test.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
98
99
100
101
102
103
104
105
106
107
#include <bits/stdc++.h>
using namespace std;
void reversed(string &s, int l, int r)
{
while (l < r)
{
swap(s[l], s[r]);
l++;
r--;
}
}
string reverseString(string str)
{
str.insert(str.end(), ' ');
int n = str.length();
int j = 0;
for (int i = 0; i < n; i++)
{
if (str[i] == ' ')
{
reversed(str, j, i - 1);
j = i + 1;
}
}
str.pop_back();
reversed(str, 0, str.length() - 1);
return str;
}
int main()
{
string str = "I like this code";
string rev = reverseString(str);
cout << rev;
return 0;
}
/*
int minimumNumber(int n, string password)
{
int con = 0;
bool a[4] = {false};
for (int i = 0; i < password.length(); i++)
{
if (password[i] >= 'A' && password[i] <= 'Z')
a[0] = true;
else if (password[i] >= 'a' && password[i] <= 'z')
a[1] = true;
else if (password[i] >= '0' && password[i] <= '9')
a[2] = true;
else
a[3] = true;
}
for (int i = 0; i < 4; i++)
if (!a[i])
con++;
return max(con, 6 - n);
}
int main()
{
cout << minimumNumber(3, "Ab1") << endl;
cout << minimumNumber(11, "#HackerRank") << endl;
return 0;
}
class Solution
{
public:
vector<string> generateParenthesis(int n)
{
vector<string> ans;
backtracking(ans, "", 0, 0, n);
return ans;
}
private:
void backtracking(vector<string> &ans, string cur_s, int open, int close, int max)
{
if (max * 2 == cur_s.size())
{
ans.push_back(cur_s);
return;
}
if (open < max)
backtracking(ans, cur_s + "(", open + 1, close, max);
if (close < open)
backtracking(ans, cur_s + ")", open, close + 1, max);
}
};
*/