题解 | #配置文件恢复#
配置文件恢复
http://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
string a;
while(getline(cin, a))
{
string b[6]={"reset","reset board","board add","board delet","reboot backplane","backplane abort"};
string e[6]={"reset what","board fault","where to add","no board at all","impossible","install first"};
int c=0;
int d;
for(int i=0;i<a.length();i++)
{
if(a[i]==' ')
{
c=1;
d=i;
break;
}
}
if(c==0)
{
int u=0;
for(int i=0;i<min(b[0].length(),a.length());i++)
{
if(b[0][i]==a[i])
{
continue;
}
else if(b[0][i]!=a[i])
{
u=1;
break;
}
}
if(u==0)
{
cout<<e[0]<<endl;
}
else
{
cout<<"unknown command"<<endl;
}
}
else if(c==1)
{
vector<int>f;
for(int i=1;i<6;i++)
{
int g=0,h=0,w=0;
for(int j=0;j<b[i].length();j++)
{
if(b[i][j]==' ')
{
for(int m=0;m<min(j,d);m++)
{
int g=1;
if(b[i][m]==a[m])
{
g=0;
}
else if(b[i][m]!=a[m])
{
g=1;
h=1;
break;
}
}
for(int m=1;m<=min(b[i].length()-1-j,a.length()-1-d);m++)
{
int g=1;
if(b[i][j+m]==a[d+m])
{
g=0;
}
else if(b[i][j+m]!=a[d+m])
{
g=1;
w=1;
break;
}
}
}
}
if(g==0&&h==0&&w==0)
{
f.push_back(i);
}
}
if(f.size()==1)
{
cout<<e[f[0]]<<endl;
}
else
{
cout<<"unknown command"<<endl;
}
}
}
return(0);
}
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
string a;
while(getline(cin, a))
{
string b[6]={"reset","reset board","board add","board delet","reboot backplane","backplane abort"};
string e[6]={"reset what","board fault","where to add","no board at all","impossible","install first"};
int c=0;
int d;
for(int i=0;i<a.length();i++)
{
if(a[i]==' ')
{
c=1;
d=i;
break;
}
}
if(c==0)
{
int u=0;
for(int i=0;i<min(b[0].length(),a.length());i++)
{
if(b[0][i]==a[i])
{
continue;
}
else if(b[0][i]!=a[i])
{
u=1;
break;
}
}
if(u==0)
{
cout<<e[0]<<endl;
}
else
{
cout<<"unknown command"<<endl;
}
}
else if(c==1)
{
vector<int>f;
for(int i=1;i<6;i++)
{
int g=0,h=0,w=0;
for(int j=0;j<b[i].length();j++)
{
if(b[i][j]==' ')
{
for(int m=0;m<min(j,d);m++)
{
int g=1;
if(b[i][m]==a[m])
{
g=0;
}
else if(b[i][m]!=a[m])
{
g=1;
h=1;
break;
}
}
for(int m=1;m<=min(b[i].length()-1-j,a.length()-1-d);m++)
{
int g=1;
if(b[i][j+m]==a[d+m])
{
g=0;
}
else if(b[i][j+m]!=a[d+m])
{
g=1;
w=1;
break;
}
}
}
}
if(g==0&&h==0&&w==0)
{
f.push_back(i);
}
}
if(f.size()==1)
{
cout<<e[f[0]]<<endl;
}
else
{
cout<<"unknown command"<<endl;
}
}
}
return(0);
}