分享

C++算法面试题:写一个函数统计一个字符串中5个元音字母各自出现的次数,要求有适合的函数原型,可以使用辅助的自定义数据类型。

 看风景D人 2014-06-15
#include <iostream>
void caculate(char* str);
int main()
{
caculate(“adiueiiuop12A121ooookkaaljlw2″);
return 0;
}
void caculate(char* str)
{ using namespace std;
int j,a,e,i,o,u;
/*a=0;e=0;i=0;o=0;u=0;*/
a=e=i=o=u=0;
for (j=0;j<strlen(str)+1;j++)
{
if(str[j]==’a’||str[j]==’A’)
a++;
if(str[j]==’e’||str[j]==’E’)
e++;
if(str[j]==’i’||str[j]==’I’)
i++;
if(str[j]==’o’||str[j]==’O’)
o++;
if(str[j]==’u’||str[j]==’U’)
u++;
}
cout<<”a=”<<a<<”times”<<endl;
cout<<”e=”<<e<<”times”<<endl;
cout<<”i=”<<i<<”times”<<endl;
cout<<”o=”<<o<<”times”<<endl;
cout<<”u=”<<u<<”times”<<endl;
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多