#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string wejscie;
int wyjscie = 0;
cin >> wejscie;
for (unsigned int i = 0; i < wejscie.size(); i++)
{
for (unsigned int j = i; j < wejscie.size(); j++)
{
int dlugosc = j - i + 1;
if (dlugosc < 3)
{
wyjscie++;
//cout << "+1 = " << wyjscie << "\n";
continue;
}
string s = wejscie.substr(i, dlugosc);
size_t a = count(s.begin(), s.end(), 'a');
size_t b = count(s.begin(), s.end(), 'b');
size_t c = count(s.begin(), s.end(), 'c');
if (a == 0 && b > 0) a = b;
else if (a == 0 && c > 0) a = c;
if (b == 0 && a > 0) b = a;
else if (b == 0 && c > 0) b = c;
if (c == 0 && a > 0) c = a;
else if (c == 0 && b > 0) c = b;
//cout << s << " : " << a << " " << b << " " << c;
if (a == b && b == c)
{
wyjscie++;
//cout << " - +1 = " << wyjscie << "\n";
continue;
}
//cout << "\n";
}
}
//cout << "\n\n";
cout << wyjscie;
return 0;
}
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 | #include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string wejscie; int wyjscie = 0; cin >> wejscie; for (unsigned int i = 0; i < wejscie.size(); i++) { for (unsigned int j = i; j < wejscie.size(); j++) { int dlugosc = j - i + 1; if (dlugosc < 3) { wyjscie++; //cout << "+1 = " << wyjscie << "\n"; continue; } string s = wejscie.substr(i, dlugosc); size_t a = count(s.begin(), s.end(), 'a'); size_t b = count(s.begin(), s.end(), 'b'); size_t c = count(s.begin(), s.end(), 'c'); if (a == 0 && b > 0) a = b; else if (a == 0 && c > 0) a = c; if (b == 0 && a > 0) b = a; else if (b == 0 && c > 0) b = c; if (c == 0 && a > 0) c = a; else if (c == 0 && b > 0) c = b; //cout << s << " : " << a << " " << b << " " << c; if (a == b && b == c) { wyjscie++; //cout << " - +1 = " << wyjscie << "\n"; continue; } //cout << "\n"; } } //cout << "\n\n"; cout << wyjscie; return 0; } |
English