<img src="https://img-blog.csdn.net/20150904154254469" alt="" />
#include <iostream>
#include <string>
using namespace std;
int Getlen(int *array, int size)
{
int j =0,cnt =0;
while(j<size)
{
if (array[j++] >=0)
{
++cnt;
}
}
return cnt;
}
int main()
{
string str;
cin>>str;
int array1[50];//存放h,u,a所在位置,从0开始
int array2[50];
int array3[50];
for(int i =0; i<50;i++)
{
array1[i] = -1;
array2[i]= -1;
array3[i] = -1;
}
int ix = 0;
int len = str.size();
int fistOfh= str.find_first_of('h',0);
int fistOfu= str.find_first_of('u',fistOfh+1);
int fistOfa= str.find_first_of('a',fistOfu+1);
if (fistOfh == string::npos || fistOfu== string::npos || fistOfa == string::npos)
{
cout<<"0"<<endl;
return 0;
}
else
{
for (int i = 0; i< len;)
{
int pos = str.find_first_of('h',i);
if (pos != string::npos)
{
array1[ix++] = pos;
i = pos + 1;
}
else
break;
}
ix =0;//ix下标重新置0
for (int i = fistOfh + 1; i< len;)
{
int pos = str.find_first_of('u',i);
if (pos != string::npos)
{
array2[ix++] = pos;
i = pos + 1;
}
else
break;
}
ix =0;//ix下标重新置0
for (int i = fistOfh + 1; i< len;)
{
int pos = str.find_first_of('a',i);
if (pos != string::npos)
{
array3[ix++] = pos;
i = pos + 1;
}
else
break;
}
}
int cnt1 = Getlen(array1,50);//获得数组中的存放的’h‘’u‘’a‘对应的个数
int cnt2 = Getlen(array2,50);
int cnt3 = Getlen(array3,50);
int num =0;
for(int i = 0; i< cnt1;i++)
for(int j=0; j<cnt2;j++)
for (int k = 0; k<cnt3;k++)
{
if (array1[i] < array2[j] && array2[j] < array3[k])
{
num++;
}
}
cout<<num<<endl;
system("pause");
return 0;
}