HDOJ1022
来源:互联网 发布:查看java进程 编辑:程序博客网 时间:2024/06/01 10:44
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;
string s1, s2;
stack<char> sta;
int main()
{
int n;
while (cin >> n)
{
getchar();
cin >> s1 >> s2;
int now = 0;
sta.push(s1[now++]);
for (int i = 0; i < s2.length(); i++)
{
while (sta.empty()||sta.top() != s2[i])
{
if (now >= s1.length())break;
sta.push(s1[now++]);
}
if (sta.top() == s2[i]) sta.pop();
}
if (!sta.empty())
{
cout << "No." << endl << "FINISH" << endl;
while (!sta.empty()) sta.pop(); //清空栈
}
else
{
cout << "Yes." << endl;
now = 0;
sta.push(s1[now++]);
cout << "in" << endl;
for (int i = 0; i < s2.length(); i++)
{
while (sta.empty() || sta.top() != s2[i])
{
if (now >= s1.length())break;
sta.push(s1[now++]);
cout << "in" << endl;
}
if (sta.top() == s2[i])
{
sta.pop();
cout << "out" << endl;
}
}
cout << "FINISH" << endl;
}
}
return 0;
}
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;
string s1, s2;
stack<char> sta;
int main()
{
int n;
while (cin >> n)
{
getchar();
cin >> s1 >> s2;
int now = 0;
sta.push(s1[now++]);
for (int i = 0; i < s2.length(); i++)
{
while (sta.empty()||sta.top() != s2[i])
{
if (now >= s1.length())break;
sta.push(s1[now++]);
}
if (sta.top() == s2[i]) sta.pop();
}
if (!sta.empty())
{
cout << "No." << endl << "FINISH" << endl;
while (!sta.empty()) sta.pop(); //清空栈
}
else
{
cout << "Yes." << endl;
now = 0;
sta.push(s1[now++]);
cout << "in" << endl;
for (int i = 0; i < s2.length(); i++)
{
while (sta.empty() || sta.top() != s2[i])
{
if (now >= s1.length())break;
sta.push(s1[now++]);
cout << "in" << endl;
}
if (sta.top() == s2[i])
{
sta.pop();
cout << "out" << endl;
}
}
cout << "FINISH" << endl;
}
}
return 0;
}
阅读全文
0 0
- HDOJ1022
- hdoj1022
- HDOJ1022
- HDOJ1022(栈)
- 堆栈练习3:HDOJ1022
- hdoj1022------------------Train Problem I---栈
- hdoj1022 Train Problem I ( stack )
- hdoj1022火车进站(栈)
- HDOJ1022 Train Problem I 栈模拟
- HDOJ1022 Train Problem I 解题报告
- hdoj1022 Train Problem I(栈的简单应用)
- PX4飞控之位置控制(1)整体架构
- 上传多个图片,并存储在session中,并且可以删除
- 常见兼容性问题
- linux堆内存漏洞利用之fastbin
- 给出一个百分制成绩,要求输出成绩等级A,B,C,D,E。90分以上为A,80~89分为B,70~79分为C,60~69分为D,60分以下为E
- HDOJ1022
- 1012. 数字分类 (20)
- macOS gdb: please check gdb is codesigned
- 在header中添加自定义属性防止CSRF
- Verilog中inout的用法(二)
- 笔试面试常考的一些小知识
- 程序员从打字开始
- 蘑菇街-应用平台开发工程师笔试编程题
- 课堂练习1(第四周)