Huawei OJ Training Problem--Configuration file Recovery (welcome discussion)

Source: Internet
Author: User

topic Category: difficulty: run time limit: memory limit: input: output: example input:
Describe:

There are 6 configuration commands, which perform the following results, respectively:

Command execution

Reset Reset What

Reset Board Board fault

Board add where to add

Board Delet no board at all

Reboot Backplane Impossible

Backplane Abort Install First

He he unkown command

Note: He and he are not commands.

In order to simplify the input, user-friendly, with the "shortest unique matching principle" match:

1. If you enter only one string, only the command line of one keyword is matched. For example input: R, according to the rule, the match command reset, the execution result is: reset what; input: res, according to the rule, match the command reset, the result of the execution is: reset what;

2. If you enter only one string, but this command has two keywords, the match fails. For example, enter: Reb, you can find the command reboot Backpalne, but the command has two keywords, all matching failed, the result is: unkown command

3, if the input two strings, first match the first keyword, if there is a match but not unique, continue to match the second keyword, if still not unique, matching failed. For example, enter: R B, locate the match command, reset board, and execute the result: board fault.

4, if the input two strings, then first match the first keyword, if there is a match but not unique, continue to match the second keyword, if unique, matching success. For example, enter: B A, unable to determine whether the command board Add or Backplane abort, the match failed.

5, if the input two strings, the first keyword match success, then match the second keyword, if there is no match, failure. For example, enter: Bo A, OK is the command board add, the match succeeds.

6. If the match fails, print "UNKONW command"

  string  
  advanced  
10sec
128mbyte
  Pre-employment practice  
 

Multiline string, one command per line

 
 

execution result, each command output one line

 
resetreset boardboard addboard deletreboot backplanebackplane abort 
Sample output:
Reset Whatboard faultwhere to Addno board at Allimpossibleinstall first

Code submitted there is a set of data, test7 do not know what test data, I hope you criticize correct ~ (to perfect)

#include <iostream> #include <string>using namespace std;/* has 6 configuration commands that perform the following results: Command execution reset reset what reset Board Board Fault Board add where to add board Delet No board @ all reboot backplane Impossible backplane abort Install First he he unkown command */static string comm1[]={"reset", "Reset What"};//0,2static string comm2[]={//5,2 "Reset board# Board fault "," board add#where to add "," board Delet#no Board @ All "," Reboot backplane#impossible "," Backplane abort# Install First "};static string comm3[]={" board fault "," where to add "," No board @ All "," impossible "," install first "};int m Ain () {string A[3];int i,j,k,secstart,flag,comm2black;int Ok[5]={0};char b[20];//getline (cin,a); while (Cin.getline (b ) {if (strlen (b) ==0) Continue;//cout<<b<<endl;flag=0;memset (ok,0,sizeof (OK)); for (I=0;i<strlen ( b); i++) {if (b[i]== ') {flag++;if (flag>1) break;secstart=i+1;}} Cout<<strlen (b) << "<<flag<<" "<<secstart<<endl;if (flag>1) {cout<<" unkown command "&LT;&LT;ENDL;} else if (flag==0) {for (I=0;i<strlen (b); i++) if (B[i]!=comm1[0][i]) {cout<< "unkown command" <<endl;break ;} if (I==strlen (b)) Cout<<comm1[1]<<endl;} else {for (j=0;j<5;j++) {for (i=0;b[i]!= "&& comm2[j][i]!="; i++) {if (b[i]!=comm2[j][i]) break;} if (b[i]== ') ok[j]=1;} for (j=0;j<5;j++) {if (ok[j]==1) {ok[j]=0;for (i=0;comm2[j][i]!= "; i++); Comm2black=i+1;for (i=secstart,k= Comm2black;i<strlen (b) && comm2[j][k]!= ' # '; i++,k++) {if (b[i]!=comm2[j][k]) break;} if (I==strlen (b)) ok[j]=1;}} for (i=0;i<5;i++)//cout<<ok[i]<< "";//cout<<endl;secstart=0;for (i=0;i<5;i++) {if (ok[i]= =1) flag=i;secstart+=ok[i];} cout<<flag<< "" <<secstart<<endl;if (secstart!=1) cout<< "unkown command" << Endl;else Cout<<comm3[flag]<<endl;}} return 0;}


Huawei OJ Training Problem--Configuration file Recovery (welcome discussion)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.