配置文件恢复(双重匹配)

#include<bits/stdc++.h>
using namespace std;
void split(char a[],vector<string>&v)
{
    char*p=strtok(a," ");
    while(p!=NULL)
    {
        string t;
        for(int i=0; i<strlen(p); i++)
            t+=p[i];
        v.push_back(t);
        p=strtok(NULL," ");
    }
}
int main()
{
    char a[1000000];
    string cmd1="reset";
    string ans1="reset what";
    string cmd_first[5]= {"reset","board","board","reboot","backplane"};
    string cmd_second[5]= {"board","add","delet","backplane","abort"};
    string ans[5]= {"board fault","where to add","no board at all","impossible","install first"};

    while(gets(a)!=NULL)
    {
        vector<string>v;
        split(a,v);
        if(v.size()==1)
        {
            if(cmd1.find(v[0])==0)
            {
                cout<<ans1<<endl;
            }
            else
            {
                cout<<"unkown command"<<endl;
            }
        }
        else if(v.size()==2)
        {
            int flag=-1;
            int i;
            for(i=0; i<5; i++)
            {
                if(cmd_first[i].find(v[0])==0&&cmd_second[i].find(v[1])==0)
                {
                    if(flag==-1)
                    {
                        flag=i;
                    }
                    else
                    {
                        cout<<"unkown command"<<endl;
                        break;
                    }
                }
            }
            if(i==5&&flag==-1)
            {
                cout<<"unkown command"<<endl;
            }
            else if(i==5&&flag!=-1)
            {
                cout<<ans[flag]<<endl;
            }
        }
        else
        {
            cout<<"unkown command"<<endl;
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值