题解 | #参数解析#

参数解析

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

#include <stdio.h>
#include <string.h>
int main() {
    char s[1001] = { 0 };
    char ss[500][100] = { 0 };
    int c = 0;
    int i = 0;
    int count = 0;
    while (scanf("%s", s) != EOF)
    {
        if (s[0] != '"')
        {
            strncpy(ss[c],s,strlen(s));
            c++;
        }
        else
        {
            int len = strlen(s);
            while (s[len - 1] != '"')
            {
                strncpy(&ss[c][i], s, strlen(s));
                i = len + i;
                ss[c][i] = ' ';
                i++;
                scanf("%s", s);
                len = strlen(s);
            }
            strncpy(&ss[c][i], s, strlen(s)-1);
            memmove(ss[c], &ss[c][1], sizeof(ss[c]) - 1);
            c++;
            i = 0;
        }
    }
    printf("%d\n", c);
    for (i = 0; i < c; i++)
    {
        printf("%s\n", ss[i]);
    }
    return 0;
}

全部评论

相关推荐

用微笑面对困难:只要你保证项目和获奖都是真的就行尤其是“对战,总负责人”啊这些套职,基本上队员,打杂的都这么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务