题解 | #参数解析#

参数解析

http://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677

#include<stdio.h>
int main() {
    char str[1002];
    while (fgets(str, 1002, stdin)) {
        int i = 0, j = 0, flag = 0, sum = 0;
        while (str[i]) {
            if (str[i] == '\"')flag = 1;
            j = i + 1;
            while (str[j] != (flag ? '\"' : ' ') && str[j] != '\n')j++;
            for (i = str[i] == '\"' ? i + 1 : i; i < j; i++);
            if (flag)j++;
            flag = 0;
            sum++;
            //printf("%c", str[i]);
        //printf("\n");
            i = j + 1;
        }
        i = 0;
        printf("%d\n", sum);
        while (str[i]) {
            if (str[i] == '\"')flag = 1;
            j = i + 1;
            while (str[j] != (flag ? '\"' : ' ') && str[j] != '\n')j++;
            for (i = str[i] == '\"' ? i + 1 : i; i < j; i++)
                printf("%c", str[i]);
            printf("\n");
            if (flag)j++;
            flag = 0;
            i = j + 1;
        }
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务