题解 | #配置文件恢复#

配置文件恢复

https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5

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

char* cmdh[5] = {"reset","board","board","reboot","backplane"};
char* cmdl[5] = {"board","add","delete","backplane","abort"};
char* cmdout[5] = {"board fault",
               "where to add",
               "no board at all",
               "impossible",
               "install first"};
char *deful = {"unknown command"};
int main() {
    char in[100];

    while(gets(in))
    {
        int index,index_o;
        int len = strlen(in);
        int flag = 0;
        int cnt = 0;
        for(int i =0;i<len;i++)
        {
            if(in[i] == ' ')
            {
                flag = 1;
                index  = i;
                break;
            }
        }

        if(flag == 1)
        {
            for(int i =0;i<5;i++)
            {
                if(strncmp(cmdh[i],in, index) == 0 && strncmp(cmdl[i],in+index+1,len-index-1) == 0)
                {
                    cnt++;
                    index_o = i;
                }
            }
            if(cnt == 1)
            {
                printf("%s\n",cmdout[index_o]);
            }else printf("%s\n",deful);
        }else if (flag == 0) {
            if(strncmp(cmdh[0], in, len) == 0)
            {
                printf("reset what\n");
            }else{
                printf("%s\n",deful);
            }
        
        }
    }
}

全部评论

相关推荐

10-15 16:27
门头沟学院 C++
LeoMoon:建议问一下是不是你给他付钱😅😅
点赞 评论 收藏
分享
牛舌:如果我不想去,不管对方给了多少,我一般都会说你们给得太低了。这样他们就会给下一个offer的人更高的薪资了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务