【leetcode】山羊拉丁文

char * toGoatLatin(char * S){
    char* buffer;
    char* retStr = (char*)calloc(2000,sizeof(char));
    char* vowel = "aeiouAEIOU";
    int pst=0,i,count=1;
    buffer = strtok(S," ");
    while(buffer) 
    {    
        //元音开头
        if (strchr(vowel,buffer[0]))
        {
            strcat(retStr,buffer);
            pst += strlen(buffer);
        }
        //辅音开头
        else
        {
            strcat(retStr,buffer+1);
            pst += strlen(buffer)-1;
            retStr[pst++] = buffer[0];
        }
        //尾部添加"ma"
        strcat(retStr,"ma");
        pst+=2;
        //尾部添加"a"
        for (i=1; i<=count; i++)
            retStr[pst++] = 'a';
        //尾部添加空格
        retStr[pst++] = ' ';
        count++;
        buffer = strtok(NULL," ");
    }
    retStr[pst-1] = '';
    return retStr;
}
原文地址:https://www.cnblogs.com/ganxiang/p/13741162.html