fork download
  1. #include<bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4. void FASTCODE() {
  5. std::ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. cout.tie(0);
  8. }
  9.  
  10. int main() {
  11. FASTCODE();
  12. int n;
  13. cin >> n;
  14. string s;
  15. cin >> s;
  16. string temp = s;
  17. int counter = 0;
  18. for (int i = 0; i < n; i++) {
  19. int fre[243] = { 0 }, arr[10] = { 0 }, r = 0;
  20. //s = temp;
  21. string x=s.substr(i, 3);
  22. sort(x.begin(),x.end());
  23. //cout << x << " ";
  24. for (int j = 0; j < 3; j++) {
  25. fre[x[j]]++;
  26. }
  27. //cout << endl;
  28.  
  29. for (int k = 48; k <= 122; k++) {
  30. if (fre[char(k)] != 0) {
  31. arr[r] = fre[char(k)];
  32. //cout << fre[char(k)] << " ";
  33. r++;
  34. }
  35. }
  36. //cout << endl;
  37. /*for(int g=0;g<r;g++){
  38.   cout << arr[g] << " ";
  39. }*/
  40.  
  41. //cout << endl;
  42. if (arr[0] == 2 && arr[1] == 1) {
  43. counter++;
  44. }
  45. else if (arr[1] == 2 && arr[0] == 1) {
  46. counter++;
  47. }
  48. else if(arr[0]==3&& arr[1]==0){
  49. counter++;
  50. }
  51. }
  52. cout << counter;
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5436KB
stdin
Standard input is empty
stdout
Standard output is empty