【十二题解】 | #配置文件恢复#
配置文件恢复
http://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
#include<stdio.h>
int zixulie(chara, charb, int alenth, int blenth){
int loc = 0;
int i;
if(a[0] != b[0])return 0;
for(i=1; i<alenth; i++){
int sign =0;
for(int j=1; j<blenth; j++){
if(a[i]==b[j] && j>loc){
loc = j;
sign = 1;
break;
}
}
if(!sign)break;
}
if(i==alenth)return 1;
return 0;
}
int order(chara, charb, charcmd1, charcmd2, int alenth, int blenth){
int ans = 0;
if(zixulie(a, cmd1[1], alenth, 5) && zixulie(b, cmd2[1], blenth, 5))ans+=10;
if(zixulie(a, cmd1[2], alenth, 5) && zixulie(b, cmd2[2], blenth, 3))ans+=100;
if(zixulie(a, cmd1[3], alenth, 5) && zixulie(b, cmd2[3], blenth, 6))ans+=1000;
if(zixulie(a, cmd1[4], alenth, 6) && zixulie(b, cmd2[4], blenth, 9))ans+=10000;
if(zixulie(a, cmd1[5], alenth, 9) && zixulie(b, cmd2[5], blenth, 5))ans+=100000;
return ans;
}
int order1(char*a, char**cmd1, int alenth){
int ans = 0;
if(zixulie(a, cmd1[0], alenth, 5))ans+=1;
return ans;
}
int main(){
char *cmd1[6] = {"reset", "reset", "board", "board", "reboot", "backplane"};
char *cmd2[6] = {"no use", "board", "add", "delete", "backplane", "abort"};
char in[28] = {0};
while(scanf("%[^\n]\n", in) != EOF){
char a1[20]={0}, a2[20]={0};
int i;
int sign = 0, loc2=0, loc1=0;
for(i=0; in[i] != '\0'; i++){
if(in[i]==' '){
sign =1;
break;
}
a1[i]=in[i];
}
loc1 = i;
if(sign){
for(i=i+1; in[i] != '\0'; i++){
a2[loc2++]=in[i];
}
}
if(sign){
int a = order(a1, a2, cmd1, cmd2, loc1, loc2);
if(a==10){
printf("board fault\n");
}
else if(a==100){
printf("where to add\n");
}
else if(a==1000){
printf("no board at all\n");
}
else if(a==10000){
printf("impossible\n");
}
else if(a==100000){
printf("install first\n");
}
else{
printf("unknown command\n");
}
}
else{
if(order1(a1, cmd1, loc1)){
printf("reset what\n");
}
else{
printf("unknown command\n");
}
}
}
}