Skip to content

Instantly share code, notes, and snippets.

@enedil
Created June 10, 2014 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enedil/1bcada5560ff79729f28 to your computer and use it in GitHub Desktop.
Save enedil/1bcada5560ff79729f28 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
int search(char a, string s);
int main()
{
ios_base::sync_with_stdio(0);
int n;
string s;
cin >> n;
cin.ignore(20, '\n');
getline(cin, s);
cout << search('z', s) + search('b', s) + search('c', s);
return 0;
}
int search(char a, string s)
{
int tmp = 0,
max = 0;
bool state = false;
for (int i = 0; i < s.length(); i++)
{
if (s[i] == a)
{
tmp++;
state = true;
if (max < tmp)
{
max = tmp;
}
}
else if (s[i] != a && state)
{
state = false;
tmp = 0;
}
}
return max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment