HDUOJ Train Problem I



#include<stdio.h>

#include<string.h>

#include<stack>

using namespace std;

stack<char> str;

char s1[9],s2[9];

int main()

{

int n;

str.push(‘#‘);

while(~scanf("%d %s %s",&n,s1,s2))

{

while(str.top()!=‘#‘)

str.pop();

int l=0,i;

for(i=0;i<n;i++)

{

str.push(s1[i]);

if(str.top()==s2[l])

{

while(str.top()==s2[l])

{

str.pop();

l++;

}

}

}

if(str.top()==‘#‘)

{

printf("Yes.\n");

l=0;

for(i=0;i<n;i++)

{

if(str.top()!=s2[l])

{

str.push(s1[i]);

printf("in\n");

if(str.top()==s2[l])

{

while(str.top()==s2[l])

{

str.pop();

printf("out\n");

l++;

}

}

}

}

printf("FINISH\n");

}

else printf("No.\nFINISH\n");

}

return 0;

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-07-31 14:34:40

HDUOJ Train Problem I的相关文章

HDU1022 Train Problem I (栈)

栈+队列 1 #include<stdio.h> 2 #include<string.h> 3 #include<stack> 4 #include<queue> 5 using namespace std; 6 int main() 7 { 8 int n; 9 char a[11],b[11]; 10 stack<char>s; 11 queue<int>q; 12 while(scanf("%d",&

hdu 1022 Train Problem

Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30588    Accepted Submission(s): 11561 Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays

Train Problem II 卡特兰裸题(入门题)

Train Problem II  题目大意:给你一个数n,表示有n辆火车,编号从1到n,从远方驶过来,问你有多少种出站的可能. 解题思路:模拟栈的问题而已.  卡特兰问题. 1 import java.math.*; 2 import java.util.*; 3 import java.io.*; 4 5 public class Main 6 { 7 static int MS=101; 8 public static void main(String[] args) 9 { 10 Sca

hdoj 1023 Train Problem II 【卡特兰】+【高精度】

题意:询问有多少种进站出站的顺序. 经典卡特兰.我对卡特兰目前的认识就是有n个1和n个-1,组成一个为2n的数列的方式有多少种.这就跟火车进站出站类似, 至于具体的卡特兰数的介绍,百度解释的很详细. 代码1(c语言): /* h(n) = h(n-1)*(4*n-2)/(n+1); */ #include <stdio.h> #include <string.h> #define M 110 int s[M][M] = {0}, b[M]; void init(){ s[1][0]

Train Problem II HDU 1023 卡特兰数

Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway. Input The input contains se

hdoj 1022 Train Problem I 【简易STL】

题意:不解释(这题是学数据结构必做的) 以前自学数据结构的时候,只是会顺序表来模拟栈.最近简单学习了stack头文件 又来做了一遍(还是以前的味道) 代码: #include <stdio.h> #include <stack> #include <string.h> using std::stack; stack<char > s; char s1[100], s2[100]; int vis[10]; char stac[100]; int main()

Train Problem II (卡特兰数+大数问题)

卡特兰数: Catalan数 原理: 令h(1)=1,h(0)=1,catalan数满足递归式: h(n)= h(1)*h(n-1) + h(2)*h(n-2) + ... + h(n-1)h(1) (其中n>=2) 另类递归式: h(n)=((4*n-2)/(n+1))*h(n-1); 该递推关系的解为: h(n+1)=C(2n,n)/(n+1) (n=1,2,3,...) 最典型的四类应用:(实质上却都一样,无非是递归等式的应用,就看你能不能分解问题写出递归式了) 1.括号化问题. 矩阵链乘

train problem I (栈水题)

杭电1002http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25276    Accepted Submission(s): 9529 Problem Description As the new term com

HDU 1022 之 Train Problem I

Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 21736    Accepted Submission(s): 8232 Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays.