题解 | #单词倒排#

单词倒排

https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836

#include <ctype.h>
#include <stdio.h>

int checkAlp(char ch)
{
    if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
        return 1;
    return 0;
}

int main() {
    char ch;
    int count = 0;
    char str[10008] = {0};
    int flag = 0;
    while(EOF != (ch = getchar()))
    {
        str[count++] = ch;
    }
    while(0 == checkAlp(str[count]))
    {
        str[count--] = '\0';
    }
    for(int i = count; i >= 0; i--)
    {
        if(0 == checkAlp(str[i])){
            printf("%s ",(str+i+1));
            str[i] = '\0';
        }
    }
    if(1 == checkAlp(str[0]))
        printf("%s",str);

    return 0;
}

全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务