题解 | #配置文件恢复#
配置文件恢复
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); } } } }