#include<stdio.h> #include<string.h> //定义两个字符串数组 char *str1[5]={"reset","board","board","reboot","backplane"}; char *str2[5]={"board","add","delete","backplane","abort"}; int main(void) { char str[100]={0}; while (gets(str)) { int len=strlen(str); int flag=0; int pos; for(int i=0;i<len;i++) { if(str[i]==' ') { flag++; pos=i; } } if(flag==0)//一字串 { char reset[20]="reset"; if(strncmp(reset,str,len)==0) { printf("reset what\n"); } else { printf("unknown command\n"); } } else if(flag==1)//两字串 { int cnt=0; int result=0; for(int i=0;i<5;i++) { if(strncmp(str,str1[i],pos)==0&&strncmp(str+pos+1,str2[i],len-pos-1)==0) { cnt++; result=i; } } if(cnt==1) { if(result==0) { printf("board fault\n"); } else if(result==1) { printf("where to add\n"); } else if(result==2) { printf("no board at all\n"); } else if(result==3) { printf("impossible\n"); } else if(result==4) { printf("install first\n"); } } else { printf("unknown command\n"); } } } return 0; }