//统计元音字母——输入一个字符串,统计处其中元音字母的数量。更复杂点的话统计出每个元音字母的数量。
#include <iostream>
using namespace std;
bool CountChar(const char* str, int* cA, int* cE, int* cI, int* cO, int* cU, int* all)
{
int len = strlen(str);
if (cA == NULL ||
cE == NULL ||
cI == NULL ||
cO == NULL ||
cU == NULL)
return false;
*cA = *cE = *cI = *cO = *cU = *all = 0;
for (int i = 0; i < len; ++i)
{
switch (str[i])
{
case 'a':
case 'A':
(*cA)++;
break;
case 'e':
case 'E':
(*cE)++;
break;
case 'o':
case 'O':
(*cO)++;
break;
case 'i':
case 'I':
(*cI)++;
break;
case 'U':
case 'u':
(*cU)++;
break;
default:
break;
}
}
*all = *cA + *cE + *cI + *cO + *cU;
return true;
}
int main(int argc, char* argv[])
{
char* str = "hello, pretty girls !";
int cA, cE, cI, cO, cU, all;
if (CountChar(str, &cA, &cE, &cI, &cO, &cU, &all))
cout << "cA:" << cA << endl
<< "cE:" << cE << endl
<< "cI:" << cI << endl
<< "cO:" << cI << endl
<< "cU:" << cU << endl
<< "all:" << all << endl;
system("pause");
return 0;
}
统计元音字母
最新推荐文章于 2023-11-28 09:29:05 发布