Rails problem
总是wa~
#include <stdio.h>
int main()
{
int n, i, j, k, atop, cmd[];
char a[], b[];
while(scanf("%d %s %s", &n, a, b) != EOF){ for(i = , j = , k = ; i < n; i++){ atop = i + ;
cmd[k++] = ;
while(atop > && a[atop - ] == b[j]){ cmd[k++] = ;
j++;
atop--; } }
if(j == n)
{ printf("Yes.\n");
for(i = ; i < k; i++){ if(cmd[i] == )
printf("in\n");
else
printf("out\n"); }
printf("FINISH\n"); }
else
{ printf("No.\nFINISH\n"); } }
return ;
}
经过修改,发现问题出现在栈的使用,调试了这组数据:5 67543 74536,才发现自己没有清栈。
#include <stdio.h>
int main()
{
int n, i, j, k, top, cmd[];
char a[], b[], c[];
while(scanf("%d %s %s", &n, a, b) != EOF){ top = ;
for(i = , j = , k = ; i < n; i++){ c[top++] = a[i];/*入栈*/
cmd[k++] = ;
while(c[top-] == b[j]){ c[top-] = ;/*出栈*/
top--;
cmd[k++] = ;
j++; } }
if(j == n)
{ printf("Yes.\n");
for(i = ; i < k; i++){ if(cmd[i] == )
printf("in\n");
else
printf("out\n"); }
printf("FINISH\n"); }
else
{ printf("No.\nFINISH\n"); } }
return ;
}
解决此问题后,写下自己的用栈心得:
入栈,先赋值再上移栈顶;
出栈,清零再下移栈顶。
注意:一定要保持栈的数目不变,这样才是栈的使用规则
Rails problem的更多相关文章
- rails work
4.2 Say "Hello", Rails problem weppack not install solve run the command rails webpacker:i ...
- OpenJudg / Poj 1363 Rails
1.链接: http://poj.org/problem?id=1363 http://bailian.openjudge.cn/practice/1363 2.题目: Rails Time Limi ...
- usaco training 4.1.2 Fence Rails 题解
Fence Rails题解 Burch, Kolstad, and Schrijvers Farmer John is trying to erect a fence around part of h ...
- Choosing web framework: ASP.NET MVC vs Django Python vs Ruby on Rails(转载)
来源:http://podlipensky.com/2012/06/choosing-web-framework-asp-net-mvc-vs-django-python-vs-ruby-on-rai ...
- 算法之路 level 01 problem set
2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 ...
- USACO 6.3 Fence Rails(一道纯剪枝应用)
Fence RailsBurch, Kolstad, and Schrijvers Farmer John is trying to erect a fence around part of his ...
- Rails NameError uninitialized constant class solution
rails nameerror uninitialized constant class will occur if your rails console is not loaded with con ...
- UVA 514 - Rails ( 铁轨)
from my CSDN: https://blog.csdn.net/su_cicada/article/details/86939523 例题6-2 铁轨(Rails, ACM/ICPC CERC ...
- USACO 4.1 Fence Rails
Fence RailsBurch, Kolstad, and Schrijvers Farmer John is trying to erect a fence around part of his ...
随机推荐
- poj2533 LIS
题目链接: http://poj.org/problem?id=2533 题意:第一个数n,接下来n个数,> ....求最长上升子序列. 这道题有两种解法,第一种是通解,也适用于别的LIS. ...
- 《DSP using MATLAB》示例Example5.5
代码: %% ---------------------------------------------------------- %% START N=5 %% ------------------ ...
- css/js(工作中遇到的问题)-2
iOS6 中的 apple-itunes-app tag 例子 //iOS6, safari才有效 <meta name="apple-itunes-app" content ...
- Transform组件C#游戏开发快速入门
Transform组件C#游戏开发快速入门大学霸 组件(Component)可以看作是一类属性的总称.而属性是指游戏对象上一切可设置.调节的选项,如图2-8所示.本文选自C#游戏开发快速入门大学霸 ...
- 05_Java异常(Exception)
1. 异常的概念 1.1什么是异常 异常指的是程序运行时出现的不正常情况. 1.2异常的层次 Java的异常类是处理运行时的特殊类,每一种异常对应一种特定的运行错误.所有Java异常类都是系统类库中E ...
- ZOJ3195 Design the city(LCA)
题目大概说给一棵树,每次询问三个点,问要把三个点连在一起的最少边权和是多少. 分几种情况..三个点LCA都相同,三个点有两对的LCA是某一点,三个点有两对的LCA各不相同...%……¥…… 画画图可以 ...
- HIT2739 The Chinese Postman Problem(最小费用最大流)
题目大概说给一张有向图,要从0点出发返回0点且每条边至少都要走过一次,求走的最短路程. 经典的CPP问题,解法就是加边构造出欧拉回路,一个有向图存在欧拉回路的充分必要条件是基图连通且所有点入度等于出度 ...
- php 从myslql里导出到excel
//导出excel 只wps可以打开public function takexcelAction(){ $name = $this->input->get_post('name'); $i ...
- (转)STORM启动与部署TOPOLOGY
STORM启动与部署TOPOLOGY 启动ZOOPKEEPER zkServer.sh start 启动NIMBUS storm nimbus & 启动SUPERVISOR storm sup ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its fi ...