forked from rohitthapliyal2000/Competitive-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwo-characters.cpp
74 lines (68 loc) · 1.44 KB
/
Two-characters.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
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int len ;
int store[1000];
int index1 = 0;
void check(string str, char a, char b)
{
string temp;
for(int i = 0; i < len; i++)
{
if(str[i] == a || str[i] == b)
{
temp = temp + str[i];
}
}
int temp_flag = 0;
for(int i = 0; i < temp.size()-1; i++)
{
if(temp[i] == temp[i+1])
temp_flag = 1;
}
if(temp_flag == 0)
store[index1++] = temp.size();
}
int main(){
cin >> len;
string str;
cin >> str;
char arr[len];
int j = 0;
int flag;
for(int i = 0; i < len; i++)
{
if(arr != "")
{
flag = 0;
for(int k = 0; k <= len; k++)
{
if(arr[k] == str[i])
{
flag = 1;
}
}
}
if(flag == 0)
arr[j++] = str[i];
}
for(int i = 0; i < len; i++)
{
for(int j = 1; j < len; j++)
{
if(arr[i] != arr[j] && arr[i] >= 'a' && arr[i] <= 'z' && arr[j] >= 'a' && arr[j] <= 'z')
{
check(str, arr[i], arr[j]);
}
}
}
int max = 0;
for(int i = 0; i < index1; i++)
{
if(store[i] > max)
max = store[i];
}
cout << max;
return 0;
}