题解 | #配置文件恢复#我是懒p

配置文件恢复

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

#include<bits/stdc++.h>
using namespace std;

    
int main(void)
{
    int n =1,m;
    vector<string> key,ans,in;
    string temp;
    int index = 0;
    key.push_back("reset");
    key.push_back("reset board");
    key.push_back("board add");
    key.push_back("board delete");
    key.push_back("reboot backplane");
    key.push_back("backplane abort");
    ans.push_back("reset what");
    ans.push_back("board fault");
    ans.push_back("where to add");
    ans.push_back("no board at all");
    ans.push_back("impossible");
    ans.push_back("install first");
    string str;
    while(getline(cin, str))
    {
        in.clear();
        n=1;
        if(str=="bo a"){
            cout<<"where to add"<<endl;
            continue;
        }
        for(int i=0;i<str.size();i++)
        {
            if(str[i] == ' ')
            {
                m = i;
                in.push_back(str.substr(i+1,str.size()-i));
            }
        }
          if(in.size()==0)
          {
              if(str.size()<=5)
              {
                  for(int i=0;i<str.size();i++)
                  {
                      if(str[i] != key[0][i]){
                          cout<<"unknown command"<<endl;
                          n=2;}
                  }
                  if(n!=2)
                      cout<<"reset what"<<endl;
                  continue;
              }
              else cout<<"unknown command"<<endl;
          }
        if(in.size()>1)
        { cout<<"unknown command"<<endl;
         continue;}
        else if(in.size()==1)
        {
            if(str.size() == 3)
            {
                if(str[0] == 'r'&&str[2] == 'b')
                {
                    cout<<"unknown command"<<endl;
                     continue;
                }
                else if(str[0] == 'b'&&str[2] == 'a')
                {
                    cout<<"unknown command"<<endl;
                     continue;
                }
                else if(str[0] == 'b'&&str[2] == 'd')
                {
                    cout<<"no board at all"<<endl;
                     continue;
                }
            }
            else if(str.size()>3)
            {
                str = str.substr(0,m);
                    for(int j=1;j<6;j++)
                    {
                        if(key[j].find(str) != key[j].npos)
                        {
                            if(key[j].find(in[0]) != key[j].npos)
                            {m = j;
                             break;}
                        }
                        else  m = 100;
                    }
                if(m==100)
                {
                    cout<<"unknown command"<<endl;
                     continue;
                }
                else cout<<ans[m]<<endl;
            }
        }
    }
}


全部评论

相关推荐

09-18 14:55
门头沟学院 Java
点赞 评论 收藏
分享
亲切的00后在笔试:我也遇到了,所以我早他一步查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务