各位大侠,请教有关C++中runtime error的问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 19:11:28
我用VC++6.0运行自己写的程序时是通过的,答案也正确,可是交到学校的网上时,它总是提示runtime error,是怎么一回事儿哈???
以下是我的程序:
#include <iostream>
using namespace std;
int main()
{
char ch1,ch2;
char a;
int an[20];
int j=0,h=0;
int precount,ltrcount;
for(int i=0;i<20;i++)
{
an[i]=0;
}
while ((a=cin.get())!='0')
{
ch1=a;
precount=ltrcount=1;
while ((a=cin.get())!='\n')
{
ch2=a;
int temp=ltrcount;
ltrcount=((ch1>'2')||((ch1=='2')&&(ch2>'6')))?ltrcount:(precount+ltrcount);
precount=temp;
ch1=ch2;
}
an[j]=ltrcount;
j++;
}
for(int h=0;h<20;h++)
{
if(an[h]!=0)
cout<<an[h]<<endl;
}
return 0;
}
谢谢lihaosky!!你上次的回答,我看不懂,不过回去看了自己买的书后解决了!我现在上面的程序做的就是上次那个问题的。这次解决了这个问题,但是新的问题出现了,它说我的答案错误,你能帮我看一下是哪里错的吗??我觉得我的算法没有错呀。(麻烦再帮忙看看,我一定会选你为最佳答案的!!)

看来你是在pku上提交,肯定是数组不够大,越界,或者指针指向了不该指的地方
..又是你,我上次回答了你怎么没反应了????-_-

估计是病毒了
http://www.baidu.com/s?wd=runtime+error

#include <iostream>
using namespace std;
int main()
{
char ch1,ch2;
char a;
int an[20];
int j=0,h=0;
int precount,ltrcount;
for(int i=0;i<20;i++)
{
an[i]=0;
}
while ((a=cin.get())!='0')
{
ch1=a;
precount=ltrcount=1;
while ((a=cin.get())!='\n')
{
ch2=a;
int temp=ltrcount;
ltrcount=((ch1>'2')||((ch1=='2')&&(ch2>'6')))?ltrcount:(precount+ltrcount);
precount=temp;
ch1=ch2;
}
an[j]=ltrcount;
j++;
}
for(h=0;h<20;h++)
{
if(an[h]!=0)
cout<<an[h]<<endl;
}
return 0;
}

可能是an[j]=ltrcount;这句,