Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <deque>
  7. #include <queue>
  8. #include <stack>
  9. #include <string>
  10. #include <bitset>
  11. #include <cstdio>
  12. #include <limits>
  13. #include <vector>
  14. #include <climits>
  15. #include <cstring>
  16. #include <cstdlib>
  17. #include <fstream>
  18. #include <numeric>
  19. #include <sstream>
  20. #include <iostream>
  21. #include <algorithm>
  22. #include <unordered_map>
  23.  
  24. using namespace std;
  25.  
  26. const int MaxN = 1024;
  27.  
  28. bool hasRightFormat(string s) {
  29. if (s.size() < 2) return false;
  30. for (int i = 2; i < s.size(); i += 2) {
  31. if (s[i] != s[0]) return false;
  32. }
  33. for (int i = 3; i < s.size(); i += 2) {
  34. if (s[i] != s[1]) return false;
  35. }
  36. return true;
  37. }
  38.  
  39. int lengthByKeepingTwoChars(string s, char a, char b) {
  40. int N = s.size();
  41. string tempStr = "";
  42. for (int i = 0; i < N; ++i) {
  43. if (s[i] != a && s[i] != b) continue;
  44. tempStr += s[i];
  45. }
  46. if (hasRightFormat(tempStr)) {
  47. return tempStr.size();
  48. }
  49. return 0;
  50. }
  51. int main(){
  52. int len;
  53. cin >> len;
  54. string s;
  55. cin >> s;
  56. int sol = 0;
  57. for (char a = 'a'; a <= 'z'; ++a) {
  58. for (char b = 'a'; b <= 'z'; ++b) {
  59. if (a == b) continue;
  60. int tempSol = lengthByKeepingTwoChars(s, a, b);
  61. if (tempSol > sol) {
  62. sol = tempSol;
  63. }
  64. }
  65. }
  66. cout << sol << "\n";
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement