回寝室之前 写了一个 小题目 aeiou 元音字母 排序

来源:互联网 发布:防闪退软件下载 编辑:程序博客网 时间:2024/04/30 09:19

#include<iostream>#include<string.h>#include <string>using namespace std;void SortVowel(const char *strInPut,char *strOutPut){    int iLen = strlen(strInPut);    char cTemp;    int iTemp = 0;    for(int i = 0; i < iLen; i++)    {        cTemp = strInPut[i];        if(cTemp == 'a'||cTemp == 'e'||           cTemp == 'i'||cTemp == 'o'||           cTemp == 'u'||cTemp == 'A'||           cTemp == 'E'||cTemp == 'I'||           cTemp == 'O'||cTemp == 'U')        {            strOutPut[iTemp++] = cTemp;        }    }    strOutPut[iTemp] = '\0' ;    for(int i = 0 ; i < (iTemp - 1) ; i++)    {       for(int j = i+1 ; j < (iTemp) ; j++ )       {           if(strOutPut[i] > strOutPut[j] )           {              cTemp = strOutPut[i];              strOutPut[i] = strOutPut[j];              strOutPut[j] = cTemp;           }       }    }    std::cout<<"First Sort :"<<strOutPut<<std::endl;;    char *strTemp = new char[strlen(strOutPut)];    int iRecode = 0;    for(int i = 0; i < strlen(strOutPut) ; i++)    {        if(strOutPut[i] >= 'a' && strOutPut[i] <= 'z')        {            strTemp[iRecode++] = strOutPut[i];        }    }    int iRecodeTemp = iRecode;    for(int i = 0; i < ( strlen(strOutPut) - iRecodeTemp ); i++)    {        strTemp[iRecode++] = strOutPut[i];    }    for(int i = 0; i < strlen(strOutPut) ; i++)    {        strOutPut[i] = strTemp[i];    }    delete[]strTemp;}int main(){    char RetBuffer[100];    SortVowel("Abort!MayBe Some Errors In Out System",RetBuffer);    std::cout << RetBuffer<<std::endl;    return 0;}


0 0
原创粉丝点击