HDU 1022 train problem I

Source: Internet
Author: User

This is a stack of questions. I started to simulate the problem with arrays. I did not make the changes in the morning and finally gave up. Later, when I was working with the white gods, the white gods found the error, it's also my mistake, like 4 1234 2134... I understand, the middle can also be out of the stack.

Store the two strings first, and then stack them first. If the stack information is generated and the car to be output is located at the top of the stack, it can be output. Otherwise, go to the stack.

# Include <stdio. h> # include <string. h> int N, C, num1 [11], num2 [11], REC [11], L [11]; int main () {int I, j, CNT, k; while (scanf ("% d", & n) = 1) {c = 0; memset (REC, 0, sizeof (REC )); for (I = 0; I <n; ++ I) scanf ("% 1D", & num1 [I]); for (I = 0; I <N; ++ I) scanf ("% 1D", & num2 [I]); j = 0; CNT = I = c =-1; L [++ C] = num1 [++ I]; // import the first vehicle into the stack rec [++ CNT] = 0; while (I <n & J <n) {While (C> = 0 & L [c] = num2 [J ]) Rec [++ CNT] = 1, -- C, ++ J; // This car is on the top of the stack, you can get out of the car rec [++ CNT] = 0, L [++ C] = num1 [++ I]; // enter the vehicle} if (I = N & J = N) {// The REC value is 0 and the REC value is 1. "); For (k = 0; k <CNT; ++ K) puts (REC [k]? "Out": "in");} else puts ("no."); puts ("finish");} return 0 ;}

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.