杭电ACM 1022 感觉是小改动 却出现Runtime Error(ACCESS_VIOLATION) 请各位帮我看看

tang21814 2010-08-03 03:54:00
请问各位 为什么这样写能AC 但是...

#include<iostream>
using namespace std;

int main()
{
int n;
while(cin>>n)
{
if(n>9)
{
cout<<"输入错误,请重新输入"<<endl;
continue;
}
char order1[100],order2[100],stack[100];
cin>>order1>>order2;
int length,i,j;
for(i=0,j=0,length=0;i!=n;)
{
if(length==0||stack[length-1]!=order2[j])//这里...
{
stack[length++]=order1[i++];
}
for(;length>0&&stack[length-1]==order2[j];)
{
--length;
++j;
}
}
if(length==0)
{
cout<<"Yes."<<endl;
for(i=0,j=0,length=0;i!=n;)
{
for(;length==0||stack[length-1]!=order2[j];)
{
stack[length++]=order1[i++];
cout<<"in"<<endl;
}
for(;length>0&&stack[length-1]==order2[j];)
{
--length;
++j;
cout<<"out"<<endl;
}
}
}
else
cout<<"No."<<endl;
cout<<"FINISH"<<endl;
}
return 0;
}


这样写却会出现
Runtime Error
(ACCESS_VIOLATION)呢?
求真相...没什么分了 都赌德国去了....
谢谢大家



#include<iostream>
using namespace std;

int main()
{
int n;
while(cin>>n)
{
if(n>9)
{
cout<<"输入错误,请重新输入"<<endl;
continue;
}
char order1[100],order2[100],stack[100];
cin>>order1>>order2;
int length,i,j;
for(i=0,j=0,length=0;i!=n;)
{
for(;length==0||stack[length-1]!=order2[j];)//和这里... {
stack[length++]=order1[i++];
}
for(;length>0&&stack[length-1]==order2[j];)
{
--length;
++j;
}
}
if(length==0)
{
cout<<"Yes."<<endl;
for(i=0,j=0,length=0;i!=n;)
{
for(;length==0||stack[length-1]!=order2[j];)
{
stack[length++]=order1[i++];
cout<<"in"<<endl;
}
for(;length>0&&stack[length-1]==order2[j];)
{
--length;
++j;
cout<<"out"<<endl;
}
}
}
else
cout<<"No."<<endl;
cout<<"FINISH"<<endl;
}
return 0;
}

...全文
415 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wei121422198 2010-09-02
  • 打赏
  • 举报
回复
到处留下我的足迹。。。。。。。
logiciel 2010-08-09
  • 打赏
  • 举报
回复
在以下循环中length和i没有受到控制

for(;length==0||stack[length-1]!=order2[j];)//和这里... {
stack[length++]=order1[i++];
printf("length=%d i=%d\n", length,i);
}

上面插条printf,用以下输入:
9 135678249 342567891
就可看到length>=100和i>=100了.
tang21814 2010-08-09
  • 打赏
  • 举报
回复
原来如此 谢谢楼上了 明白了!
谢谢!
tang21814 2010-08-08
  • 打赏
  • 举报
回复
依然求解 依然顶一下....
tang21814 2010-08-06
  • 打赏
  • 举报
回复
i!=n i不是在这里有控制吗..?还是没整明白 继续求解...谢谢了
[Quote=引用 4 楼 logiciel 的回复:]
请试以下输入:
9 135678249 342567891

AC的程序在以下语句
if(length==0||stack[length-1]!=order2[j])//这里...
只执行一次。

而出错的程序在以下语句
for(;length==0||stack[length-1]!=order2[j];)//和这里...
可能执行多次,导致length>=100或i>=100……
[/Quote]
logiciel 2010-08-03
  • 打赏
  • 举报
回复
请试以下输入:
9 135678249 342567891

AC的程序在以下语句
if(length==0||stack[length-1]!=order2[j])//这里...
只执行一次。

而出错的程序在以下语句
for(;length==0||stack[length-1]!=order2[j];)//和这里...
可能执行多次,导致length>=100或i>=100,所以出现ACCESS_VIOLATION。
tang21814 2010-08-03
  • 打赏
  • 举报
回复
再求解 再顶一下.....
tang21814 2010-08-03
  • 打赏
  • 举报
回复
求解 顶一下....
tang21814 2010-08-03
  • 打赏
  • 举报
回复
题目帖上来 麻烦大家了

Train Problem I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3651 Accepted Submission(s): 1326


Problem DescriptionAs 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 only one railway where all the trains stop. So all the trains come in from one side and get out from the other side. For this problem, if train A gets into the railway first, and then train B gets into the railway before train A leaves, train A can't leave until train B leaves. The pictures below figure out the problem. Now the problem for you is, there are at most 9 trains in the station, all the trains has an ID(numbered from 1 to n), the trains get into the railway in an order O1, your task is to determine whether the trains can get out in an order O2.

InputThe input contains several test cases. Each test case consists of an integer, the number of trains, and two strings, the order of the trains come in:O1, and the order of the trains leave:O2. The input is terminated by the end of file. More details in the Sample Input.
OutputThe output contains a string "No." if you can't exchange O2 to O1, or you should output a line contains "Yes.", and then output your way in exchanging the order(you should output "in" for a train getting into the railway, and "out" for a train getting out of the railway). Print a line contains "FINISH" after each test case. More details in the Sample Output.

Sample Input
3 123 321
3 123 312

Sample Output
Yes.
in
in
in
out
out
out
FINISH
No.
FINISH
源码下载地址: https://pan.quark.cn/s/8d2c461c797c JavaWeb程序设计构成了掌握Web交互式应用程序开发的核心领域,对于初学者来说,精通这一技术具有决定性意义。在“JavaWeb程序设计(第三版)作业答案”中,我们可以预期获得针对该教材习题的一系列深入解析,从而协助学习者强化知识体系。 JavaWeb所包含的技术组件涵盖了Servlet、JSP(JavaServer Pages)、JDBC(Java Database Connectivity)以及各类框架如Spring MVC、Struts等。Servlet是Java平台提供的一种扩展服务器功能的接口,能够处理HTTP求并生成相应的反馈。JSP则是一种用于构建动态网页的工具,它支持开发者将HTML代码与Java代码进行整合编写,从而简化了Web应用程序的开发流程。 作业答案通常会涉及以下几个核心内容: 1. **Servlet基础**:可能包含Servlet生命周期、init(), service(), destroy()方法的应用,以及如何在web.xml文件中设定Servlet的映射关系。 2. **JSP基础**:JSP的九大内置对象,如request、response、session、application等的使用,以及EL(Expression Language)和JSTL(JavaServer Pages Standard Tag Library)的实际操作。 3. **HTTP协议理解**:GET和POST求方法的差异,求头与响应头的应用,以及会话管理的概念阐释。 4. **JDBC数据库操作**:与数据库建立连接,执行SQL指令,处理查询结果集,以及...
源码链接: https://pan.quark.cn/s/a4b39357ea24 斐讯K2是一款广受用户青睐的无线路由器,其运行表现稳定且具备较高的可操作性,在DIY爱好者群体中拥有极高的声誉。本资料将系统性地阐述斐讯K2的固件刷机方法及其关联的技术要点。固件升级是路由器爱好者改善设备性能、扩展功能的一种普遍手段,经由替换出厂固件,能够达成更加个性化的网络配置、增强安全防护等目标。斐讯K2固件资源库涵盖了多种知名的非官方固件,诸如Tomato Pheonix 不死鸟、高恪、PandoraBox 潘多拉等,这些固件均具备独特的优势,能够适配不同用户的需求。 1. Tomato Pheonix 不死鸟:Tomato是一款立足于Linux的开源固件,以其精巧、高效而备受推崇。不死鸟版本是专门为华硕及斐讯路由器优化的分支,提供了卓越的QoS(服务质量)配置、详尽的图表监控以及便捷的固件升级途径。对于那些需要精准调控带宽和监测网络状态的用户而言,这是一个理想的选项。 2. 高恪:高恪固件是OpenWrt的定制化版本,着重于操作的便捷性和运行的可靠性,特别适合对路由器操作不甚熟悉的用户群体。它提供了一些实用的功能,例如内置的广告屏蔽、快速测速工具等,同时保留了OpenWrt的适应性。 3. PandoraBox 潘多拉:潘多拉盒是另一款基于OpenWrt的固件,它以丰富的插件库和强大的自定义潜力而闻名。用户能够依据个人需求安装各类插件,实现更多功能,如远程接入、DDNS(动态域名解析服务)等。 4. 官方固件的纯净版本与定制版本:官方固件通常更侧重于稳定性,纯净版意味着未预置额外的应用或服务,适合注重稳定性的用户。定制版则可能包含了制造商的特色功能或优...

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧