时间限制超出错误 [英] Time limit exceeded error

查看:118
本文介绍了时间限制超出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
int main(void)
{
  int i,j;
  i=0;
  int big;
  int a[9]={1,2,3,1,4,5,2,3,6};
  for(i=0;i<9;i++)
  {
  	j=i;
  	while(j<(j+2))
  	{
  		if(a[j]>a[j+1])
  		{
  			big=a[j];
  		}
  		else
  		{
  			big=a[j+1];
  		}
  		j++;
  	}
  	printf("%d",big);
  }
return 0;
}





我将超出时间限制作为输出。有人可以帮我解决一下如何删除这个bug吗?



我尝试了什么:



我甚至评论了for循环部分,但仍然是我得到的相同输出。

任何人都可以建议可能的原因是什么?



I am getting the Time Limit Exceeded as output. Can someone please help me out on how this bug can be removed?

What I have tried:

I have even commented out the for loop part but still the same output I am getting.
Can anyone please suggest what can be the possible cause of this?

推荐答案

我不知道超出时间限制的错误是什么,但这一行:



而(j<(j + 2))



不可能是真的,所以你有一个无限循环。



Matt
I don't know what a "Time Limit Exceeded" error is, but this line:

while(j<(j+2))

can't ever be true, so you have an infinite loop.

Matt


您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。

调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]



调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。 />
当代码不做ex的时候你已经接近了一个错误。
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.


这篇关于时间限制超出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆