Train Problem I

http://acm.hdu.edu.cn/showproblem.php?pid=1022

栈的模板题。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<stack>
 4 #include<string>
 5 #include<cstring>
 6 using namespace std;
 7 string a,b;
 8 int c[100];
 9 int main()
10 {
11     //  freopen("1.txt","r",stdin);
12     int n;
13     stack<char>jk;
14     while(scanf("%d",&n)!=EOF)
15     {
16         stack<int>jk;
17         while(!jk.empty())
18             jk.pop();
19         cin>>a>>b;
20         int k=0,j=0;
21         for(int i=0; i<n; i++)
22         {
23             jk.push(a[i]);
24             c[k++]=1;
25             while(j<n && !jk.empty())
26             {
27                 if(jk.top()==b[j])
28                 {
29                     j++;
30                     jk.pop();
31                     c[k++]=0;
32                 }
33                 else
34                     break;
35             }
36         }
37
38         if(jk.empty())
39         {
40             cout<<"Yes."<<endl;
41             for(int i=0; i<k; i++)
42             {
43                 if(c[i]==1)
44                     cout<<"in"<<endl;
45                 else
46                     cout<<"out"<<endl;
47             }
48             cout<<"FINISH"<<endl;
49         }
50         else
51             cout<<"No."<<endl<<"FINISH"<<endl;
52     }
53     return 0;
54 }

 

时间: 2024-09-17 04:31:09

Train Problem I的相关文章

C - Train Problem II——(HDU 1023 Catalan 数)

传送门 Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7616    Accepted Submission(s): 4101 Problem Description As we all know the Train Problem I, the boss of the Ignatius Train

算法题:HDU 1022 Train Problem I 栈

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

HDOJ/HDU 1022 Train Problem I(模拟栈)

Problem Description 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

HDU 1022

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

UVA10806&amp;#160;用SPFA

Problem ?Dijkstra, Dijkstra.Time Limit: 10 seconds   Dexter: "You don't understand. I can't walk... they've tied my shoelaces together." Topper Harley: "A knot. Bastards!" Jim Abrahams and Pat Proft, "Hot Shots! Part Deux." Y

UVa 299 Train Swapping:冒泡排序的次数

299 - Train Swapping Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=235 At an old railway station, you may still encounter one of the last remaining ``tr

训练集(train set) 验证集(validation set) 测试集(test set)

在有监督(supervise)的机器学习中,数据集常被分成2~3个,即:训练集(train set) 验证集(validation set) 测试集(test set). http://blog.sina.com.cn/s/blog_4d2f6cf201000cjx.html 一般需要将样本分成独立的三部分训练集(train set),验证集(validation set)和测试集(test set).其中训练集用来估计模型,验证集用来确定网络结构或者控制模型复杂程度的参数,而测试集则检验最终选

(zhuan) How to Train Neural Networks With Backpropagation

this blog from: http://blog.demofox.org/2017/03/09/how-to-train-neural-networks-with-backpropagation/   How to Train Neural Networks With Backpropagation Posted on March 9 2017 by Demofox This post is an attempt to demystify backpropagation, which is

C++ little errors , Big problem

------------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------------------------------------------------------------------------