参考 https://www.nowcoder.com/profile/790387376/codeBookDetail?submissionId=114290488

代码

#include<stdio.h>
#include<string.h>

int main(void)
{
    int count, i, len, flg;
    char cmdin[1000];
    while(gets(cmdin))
    {
        len = strlen(cmdin);
        flg = 0;
        count = 1;
        //参数个数
        for (i=0; i<len; i++)
        {
            if((flg==0) && (cmdin[i] == '"'))
            {
                flg = 1;
            }
            else if((flg==1) && (cmdin[i] == '"'))
            {
                flg = 0;
            }
            else if((flg==0) && (cmdin[i] == ' '))
                count++;
        }
        
        printf("%d\n", count);
        for (i=0; i<len; i++)
        {
            if((flg==0) && (cmdin[i] == '"'))
            {
                flg = 1;
            }
            else if((flg==1) && (cmdin[i] == '"'))
            {
                flg = 0;
            }
            else if((flg==0) && (cmdin[i] != ' '))
                printf("%c", cmdin[i]);
            else if((flg==0) && (cmdin[i] == ' '))
                printf("\n");
            else if(flg==1)
                printf("%c", cmdin[i]);
        }
        printf("\n");
    }
    
    return 0;
}