日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

NYOJ 150 Train Problem I STL栈

發(fā)布時(shí)間:2025/3/16 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NYOJ 150 Train Problem I STL栈 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Train Problem I

時(shí)間限制:3000?ms ?|? 內(nèi)存限制:65535?KB 難度:2 描述
As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a problem, there is only one railway where all the trains stop. So all the trains come in from one side and get out from the other side. For this problem, if train A gets into the railway first, and then train B gets into the railway before train A leaves, train A can't leave until train B leaves. The pictures below figure out the problem. Now the problem for you is, there are at most 9 trains in the station, all the trains has an ID(numbered from 1 to n), the trains get into the railway in an order O1, your task is to determine whether the trains can get out in an order O2.
輸入
The input contains several test cases. Each test case consists of an integer, the number of trains, and two strings, the order of the trains come in:O1, and the order of the trains leave:O2. The input is terminated by the end of file. More details in the Sample Input.
輸出
The output contains a string "No." if you can't exchange O2 to O1, or you should output a line contains "Yes.", and then output your way in exchanging the order(you should output "in" for a train getting into the railway, and "out" for a train getting out of the railway). Print a line contains "FINISH" after each test case. More details in the Sample Output.
樣例輸入
3 123 321 3 123 312

樣例輸出

Yes. in in in out out out FINISH No. FINISH

題意:給出兩個(gè)字符串,問第一個(gè)字符串能否經(jīng)過棧轉(zhuǎn)化為第二個(gè)字符串。?如果可以,輸出進(jìn)棧和出棧的順序。

? ? ? 這是一個(gè)關(guān)于棧的問題。棧是允許在同一端進(jìn)行插入和刪除操作的特殊線性表。允許進(jìn)行插入和刪除操作的一端稱為棧頂(top),另一端為棧底(bottom);棧底固定,而棧頂浮動(dòng);棧中元素個(gè)數(shù)為零時(shí)稱為空棧。插入一般稱為進(jìn)棧(PUSH),刪除則稱為退棧(POP)。棧也稱為后進(jìn)先出表。

#include<stdio.h> #include<string.h> #include<stack> /*定義棧*/ using namespace std; /*千萬(wàn)不要忘記*/ int main() {int n,i,j,k,flag[20];char s1[10],s2[10];stack<char> s;while(~scanf("%d%s %s",&n,s1,s2)){memset(flag,-1,sizeof(flag));j=k=0;for(i=0;i<n;i++){s.push(s1[i]);flag[k++]=1; /*1為進(jìn)棧,in*/while(!s.empty()&&s.top()==s2[j]) /*棧非空且棧頂元素與s2中的元素相等*/{flag[k++]=0; /*0為出棧,out*/s.pop(); /*清除棧頂元素*/j++; /*與s2中的下一個(gè)元素比較*/}}if(j==n) /*可以轉(zhuǎn)換*/{printf("Yes.\n");for(i=0;i<k;i++){if(flag[i]) /*flag[i]==1*/printf("in\n");elseprintf("out\n");}printf("FINISH\n");}else /*不能轉(zhuǎn)換*/printf("No.\nFINISH\n");}return 0; }

總結(jié)

以上是生活随笔為你收集整理的NYOJ 150 Train Problem I STL栈的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。