#include <iostream>
#include <algorithm>
using namespace std;
void sprawdzarka(string temp, int &count){
int a=0,b=0,c=0;
string temp2;
for(int i=0; i<temp.size(); i++){
temp2 = temp[i];
if(temp2=="a"){
a += 1;
}else if(temp2=="b"){
b += 1;
}else{
c += 1;
}
}
int tab[3] = {a,b,c};
sort(begin(tab), end(tab));
c = tab[0];
b = tab[1];
a = tab[2];
if(a==b && b==c){
count +=1;
}
else if(a==b && c==0){
count +=1;
}else if(b==0 && c==0){
count +=1;
}
}
int main(){
string input;
input = "aabbabcccba";
int count=0;
string temp;
for(int x=0; x<input.size(); x++){
for(int j=input.size()-x; j>0; j--){
temp = "";
for(int i=x; i<=input.size()-j; i++){
temp += input[i];
}
sprawdzarka(temp, count);
}
}
cout << count << endl;
}
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 56 57 58 | #include <iostream> #include <algorithm> using namespace std; void sprawdzarka(string temp, int &count){ int a=0,b=0,c=0; string temp2; for(int i=0; i<temp.size(); i++){ temp2 = temp[i]; if(temp2=="a"){ a += 1; }else if(temp2=="b"){ b += 1; }else{ c += 1; } } int tab[3] = {a,b,c}; sort(begin(tab), end(tab)); c = tab[0]; b = tab[1]; a = tab[2]; if(a==b && b==c){ count +=1; } else if(a==b && c==0){ count +=1; }else if(b==0 && c==0){ count +=1; } } int main(){ string input; input = "aabbabcccba"; int count=0; string temp; for(int x=0; x<input.size(); x++){ for(int j=input.size()-x; j>0; j--){ temp = ""; for(int i=x; i<=input.size()-j; i++){ temp += input[i]; } sprawdzarka(temp, count); } } cout << count << endl; } |
English