描述 | 有6條配置命令,它們執行的結果分別是:ios
注意:he he不是命令。ide 爲了簡化輸入,方便用戶,以「最短惟一匹配原則」匹配: 四、若輸入兩字串,則先匹配第一關鍵字,若是有匹配但不惟一,繼續匹配第二關鍵字,若是惟一,匹配成功。例如輸入:b a,沒法肯定是命令board add仍是backplane abort,匹配失敗。
|
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
知識點 | |||||||||||||||||
運行時間限制 | 0M | ||||||||||||||||
內存限制 | 0 | ||||||||||||||||
輸入 | 多行字符串,每行字符串一條命令blog |
||||||||||||||||
輸出 | 執行結果,每條命令輸出一行ip |
||||||||||||||||
樣例輸入 | reset內存 reset boardci board add字符串 board deletget reboot backplane backplane abort |
||||||||||||||||
樣例輸出 | reset what board fault where to add no board at all impossible install first |
#include<iostream> #include<vector> #include<string.h> #include<stdio.h> using namespace std; char execution[7][50] = {"reset what", "board fault", "where to add", "no board at all", "impossible", "install first", "unkown command"}; unsigned int num[7] = {1,2,2,2,2,2,0}; char command[6][2][50] = { {"reset", "xx"},\ {"reset", "board"},\ {"board", "add"},\ {"board", "delet"},\ {"reboot", "backplane"},\ {"backplane", "abort"} }; bool compare(vector<char*> &v, int idx) { //cout<<idx<<"idx"<<endl; if(v.size()==num[idx]) { for(int i=0; i<num[idx]; i++) { int sz = strlen(v[i]); //cout<<v[i]<<"display"<<endl; for(int j=0; j<sz; j++) { if(v[i][j] != command[idx][i][j]) { //cout<<v[i][j]<<"_vs_"<<command[idx][i][j]<<endl; return false; } } } return true; } else { //cout<<"size not compatible"<<endl; return false; } } void divide(char *buf) { vector<char *> v; int last = 0; int siz = strlen(buf); for(int i=0; i<=siz; i++) { if(i==0) { } else { if(buf[i]!=' ' && buf[i-1]==' ') { last = i; } if( (buf[i]==' ' || buf[i]=='\0') && buf[i-1]!=' ') { char *tmp; tmp = new char [50]; int count = 0; for(int j=last; j<i; j++) { tmp[count] = buf[j]; count++; } tmp[count] = '\0'; v.push_back(tmp); } } } /* for(int i=0; i<v.size(); i++) { cout<<v[i]<<'_'; } cout<<endl; */ if(v.size() > 2) { cout<<execution[6]<<endl;//<<"xx"; return ; } else { int howmany=0; int theone= 0; for(int i=0; i<6; i++) { if( compare(v, i) ) { howmany++; theone = i; } else { } } if(howmany==1) { cout<<execution[theone]<<endl; } else { cout<<execution[6]<<endl; } return; } } void solve(char *buf) { divide(buf); } bool allkong(char *buf) { for(int i=0; buf[i]!='\0'; i++) { if(buf[i]!=' ') return false; } return true; } int main() { char buf[100]; while( cin.getline(buf,100) ) { if(strlen(buf)>0 ) solve(buf); } return 0; }