Uva514——Rails
程序员文章站
2024-03-20 20:52:28
...
考栈的简单应用。书本的答案有点小错误。
#include<cstdio>
#include<stack>
using namespace std;
const int MANX = 1010;
int n, c[MANX];
int main()
{
while (scanf("%d",&n)==1)
{
while (scanf("%d", &c[1])==1)
{
if (!c[1])
{
printf("\n");
break;
}
for (int i = 2; i <= n; i++)
{
scanf("%d", &c[i]);
}
int a = 1, b = 1, ok = 1;
stack<int> s;
while (b<=n)
{
if (a == c[b]) { a++; b++; }
else if (!s.empty() && s.top() == c[b]) { s.pop(); b++; }
else if (a <= n) { s.push(a++); }
else
{
ok = 0; break;
}
}
printf("%s\n", ok ? "Yes" : "No");
}
}
return 0;
}
上一篇: MySQL优化之主从复制
推荐阅读
-
Uva514——Rails
-
UVa514-Rails-铁轨--栈的使用
-
如何用nginx+passenger部署Rails(转) 博客分类: rails nginxRailsrubygems配置管理Apache
-
[转贴]About ruby’s “open class” 博客分类: Ruby on Rails & Ajax Rubyrubygems.netBlog
-
Rails on Ubuntu 博客分类: Scripts RailsUbuntuRubyrubygemsMySQL
-
关于Rails的用户认证
-
Ruby on Rails 体验之旅(一)--安装 博客分类: Ruby On Rails rubyrailsrubygemssqliteweb
-
Could not find rake-0.9.2 in any of the sources Run `bundle install` to install 博客分类: rails rubyrailsrubygems
-
Ruby On Rails和locomotiveCMS安装经历 博客分类: RubyOnRails RubyUbuntuRailsCMSrubygems
-
rails 1.8.7 环境如何配制 博客分类: rails rubyrailsrubygems