Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <map>
- #include <set>
- #include <list>
- #include <cmath>
- #include <ctime>
- #include <deque>
- #include <queue>
- #include <stack>
- #include <string>
- #include <bitset>
- #include <cstdio>
- #include <limits>
- #include <vector>
- #include <climits>
- #include <cstring>
- #include <cstdlib>
- #include <fstream>
- #include <numeric>
- #include <sstream>
- #include <iostream>
- #include <algorithm>
- #include <unordered_map>
- using namespace std;
- const int MaxN = 1024;
- bool hasRightFormat(string s) {
- if (s.size() < 2) return false;
- for (int i = 2; i < s.size(); i += 2) {
- if (s[i] != s[0]) return false;
- }
- for (int i = 3; i < s.size(); i += 2) {
- if (s[i] != s[1]) return false;
- }
- return true;
- }
- int lengthByKeepingTwoChars(string s, char a, char b) {
- int N = s.size();
- string tempStr = "";
- for (int i = 0; i < N; ++i) {
- if (s[i] != a && s[i] != b) continue;
- tempStr += s[i];
- }
- if (hasRightFormat(tempStr)) {
- return tempStr.size();
- }
- return 0;
- }
- int main(){
- int len;
- cin >> len;
- string s;
- cin >> s;
- int sol = 0;
- for (char a = 'a'; a <= 'z'; ++a) {
- for (char b = 'a'; b <= 'z'; ++b) {
- if (a == b) continue;
- int tempSol = lengthByKeepingTwoChars(s, a, b);
- if (tempSol > sol) {
- sol = tempSol;
- }
- }
- }
- cout << sol << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement