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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string wyraz;
    cin>>wyraz;
    wyraz="a"+wyraz;
    int n=wyraz.size();
    int i, j, p, x=0, t[3];
    bool poza;
    for (i=0; i<n; i++)
    {
        for (j=0; j<n-i; j++)
        {
            p=int(wyraz[i+j])-97;
            t[p]++;
            poza=false;
            if (t[0]!=0 && t[1]!=0 && t[2]!=0)
            {
                if (t[0]==t[1] && t[1]==t[2] && t[2]==t[0]) poza=true;
                else poza=false;
            }
            else
            {
                if (t[0]==0)
                {
                    if (t[1]==0 && t[2]!=0) //zerowe 0 i 1
                    {
                        poza=true;
                    }
                    else
                    {
                        if (t[1]!=0 && t[2]==0) //zerowe 0 i 2
                        {
                            poza=true;
                        }
                        else
                        {
                            if (t[1]==t[2]) poza=true; //zerowe 0
                            else poza=false;
                        }
                    }
                }
                else
                {
                    if (t[1]==0 && t[2]==0) //zerowe 1 i 2
                    {
                        poza=true;
                    }
                    else
                    {
                        if (t[1]!=0 && t[2]==0) //zerowe 2
                        {
                            if (t[0]==t[1]) poza=true;
                            else poza=false;
                        }
                        else
                        {
                            if (t[1]==0 && t[2]!=0) //zerowe 1
                            {
                                if (t[0]==t[2]) poza=true;
                                else poza=false;
                            }
                        }
                    }
                }
            }
            if (poza) x++;
        }
        for (j=0; j<3; j++)
        {
            t[j]=0;
        }
    }
    cout<<x;
}