City of Angels 2821

Source: Internet
Author: User

City of Angels 2821
City of Angels 2821

 

Time Limit: 1 s space limit: 128000 KB title level: Gold Question View running resultsDescription Description

There is A railway station in Angel City. Every train enters the station from,
Then exit the station from B.

 

To schedule trains, the railway station has parking tracks and can store 5 trains. It is known that the order from A to the station is 1, 2, 3 ....... Now we will give you a scheduling scheme to determine whether it is feasible. If it is feasible, output the outbound order.
There are several Scheduling Methods:
A. Drive the first car on A out of B.
B. Park the first car on A into the suspended track
C. The outermost car on the track will be suspended from B.

Input description Input Description

Enter an integer N (n <30) in the first line to indicate the number of scheduling solution steps.
The next line is a string with N uppercase letters, indicating the scheduling method.

Output description Output Description

If the output is not feasible (when the parking stop is full or the parking stop is empty), the output line is "No ".
If feasible, output a line of "Yes" and then several rows. Each line has an integer, indicating the train-out sequence.

Sample Input Sample Input

[Example input 1]
6
ABBCCA
[Example input 2]
5
BACAC

 

Sample output Sample Output

[Sample output 1]
Yes
1
3
2
4
[Sample output 2]
No

Data range and prompt Data Size & Hint

Example

CATEGORY tag Tags click here to expand
1 # include <iostream> 2 using namespace std; 3 int stack [10001]; 4 int top = 0; 5 int now = 1; // indicates the nth car 6 int cur = 1; // indicates the number of outgoing cars 7 int ans [10001]; 8 int main () 9 {10 int n; 11 cin> n; 12 for (int I = 1; I <= n; I ++) 13 {14 char a; // Scheduling Method 15 cin>; 16 if (a = 'A') 17 {18 ans [cur] = now; 19 cur ++; 20 now ++; 21 continue; 22} 23 else if (a = 'B') 24 {25 if (top = 5) 26 {27 cout <"No"; 28 return 0; 29} 30 else31 {32 stack [top] = now; 33 now ++; 34 top ++; 35} 36} 37 else if (a = 'C ') 38 {39 ans [cur] = stack [top-1]; 40 cur ++; 41 top --; 42} 43 44} 45 if (top <0) 46 {47 cout <"No"; 48 return 0; 49} 50 else51 {52 cout <"Yes" <endl; 53 for (int I = 1; I <= cur-1; I ++) 54 {55 cout <ans [I] <endl; 56} 57} 58 return 0; 59}

 

Related Article

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.