首页 > ACM题库 > HDU-杭电 > Hdu 1644 Car Trialling 待解决 [解题报告] C++
2013
12-21

Hdu 1644 Car Trialling 待解决 [解题报告] C++

Car Trialling

问题描述 :

Car trialling requires the following of carefully worded instructions. When setting a trial, the organiser places traps in the instructions to catch out the unwary.

Write a program to determine whether an instruction obeys the following rules, which are loosely based on real car trialling instructions. BOLD-TEXT indicates text as it appears in the instruction (case sensitive), separates options of which exactly one must be chosen, and .. expands, so A..D is equivalent to A B C D .

instruction = navigational time-keeping navigational AND time-keeping

navigational = directional navigational AND THEN directional

directional = how direction how direction where

how = GO GO when KEEP

direction = RIGHT LEFT

when = FIRST SECOND THIRD

where = AT sign

sign = "signwords"

signwords = s-word signwords s-word

s-word = letter s-word letter

letter = A..Z .

time-keeping = record change

record = RECORD TIME

change = cas TO nnn KMH

cas = CHANGE AVERAGE SPEED CAS

nnn = digit nnn digit

digit = 0..9 Note that s-word and nnn are sequences of letters and digits respectively, with no intervening spaces. There will be one or more spaces between items except before a period (.), after the opening speech marks or before the closing speech marks.

输入:

Each input line will consist of not more than 75 characters. The input will be terminated by a line consisting of a single #.

输出:

The output will consist of a series of sequentially numbered lines, either containing the valid instruction, or the text Trap! if the line did not obey the rules. The line number will be right justified in a field of 3 characters, followed by a full-stop, a single space, and the instruction, with sequences of more than one space reduced to single spaces.

样例输入:

KEEP LEFT AND THEN GO RIGHT
CAS TO 20 KMH
GO FIRST       RIGHT AT "SMITH ST."  AND   CAS TO 20 KMH
GO 2nd RIGHT
GO LEFT AT "SMITH STREET AND RECORD TIME
KEEP RIGHT AND THEN RECORD TIME
#

样例输出:

  1. KEEP LEFT AND THEN GO RIGHT
  2. CAS TO 20 KMH
  3. GO FIRST RIGHT AT "SMITH ST." AND CAS TO 20 KMH
  4. Trap!
  5. Trap!
  6. Trap!


  1. 可以根据二叉排序树的定义进行严格的排序树创建和后序遍历操作。如果形成的排序树相同,其树的前、中、后序遍历是相同的,但在此处不能使用中序遍历,因为,中序遍历的结果就是排序的结果。经在九度测试,运行时间90ms,比楼主的要快。

  2. /*
    * =====================================================================================
    *
    * Filename: 1366.cc
    *
    * Description:
    *
    * Version: 1.0
    * Created: 2014年01月06日 14时52分14秒
    * Revision: none
    * Compiler: gcc
    *
    * Author: Wenxian Ni (Hello World~), [email protected]
    * Organization: AMS/ICT
    *
    * =====================================================================================
    */

    #include
    #include

    using namespace std;

    int main()
    {
    stack st;
    int n,i,j;
    int test;
    int a[100001];
    int b[100001];
    while(cin>>n)
    {
    for(i=1;i>a[i];
    for(i=1;i>b[i];
    //st.clear();
    while(!st.empty())
    st.pop();
    i = 1;
    j = 1;

    while(in)
    break;
    }
    while(!st.empty()&&st.top()==b[j])
    {
    st.pop();
    j++;
    }
    }
    if(st.empty())
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    return 0;
    }