简体   繁体   English

为什么我在ideone和codechef编译器中而不是在我的终端中遇到运行时错误?

[英]Why i'm getting runtime error in ideone and codechef compiler and not in my terminal?

I have just started competitive programming in SPOJ.I'm confused from sometime why i'm getting runtime error in ideone .The question is: 我刚开始在SPOJ中进行竞争性编程。我很困惑,为什么我会在ideone遇到runtime error 。问题是:

A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. 如果正整数在从左到右和从右到左读取时在十进制系统中的表示相同,则称为回文。 For a given positive integer K of not more than 1000000 digits, write the value of the smallest palindrome larger than K to output. 对于给定的正整数K不超过1000000位,写入大于K的最小回文值输出。 Numbers are always displayed without leading zeros. 始终显示数字而不带前导零。

Input 输入

The first line contains integer t, the number of test cases. 第一行包含整数t,测试用例的数量。 Integers K are given in the next t lines. 整数K在下一个t行中给出。

Output 产量

For each K, output the smallest palindrome larger than K. 对于每个K,输出大于K的最小回文。

Example

Input: 输入:
2 2
808 808
2133 2133

Output: 输出:
818 818
2222 2222
My program: 我的节目:

  #include <stdio.h>

  int main(void)
 {
   int t,i,reverse,same;

   scanf("%d",&t);  //t is no. of test cases

     int num[t];  //num[t] is array of t elements

   for(i=0;i<t;i++)
    scanf("%d",&num[i]);

   i=0;     //since i will be equal to t therefore i is assigned to 0.

   while(t--)
   {    
    if(num[i]<=1000000)  
    {
    while(num[i]++)
        {
         reverse=0;
         same=num[i];     

         while(same>0)
         {
          reverse=reverse*10;
          reverse=reverse+same%10;
          same=same/10;
         }
     if(reverse==num[i])
      printf("%d",reverse);

     printf("\n");

     if(reverse==num[i])
      break;
     }
    }
    i++;     
   }
  return 0;
 }

I don't know where i'm wrong.I'm sorry i'm asking this question may this question is asked by someone before.I tried to find the result but could not get the answer. 我不知道我哪里错了。对不起我问这个问题可能这个问题是有人问过的。我试图找到结果却得不到答案。 Thankyou in advance and sorry for my bad english. 提前 谢谢 ,抱歉我的英语不好。

The question doesn't say that the number will be less than 1000000. It says that the number has less than 1 million digits . 问题并不是说这个数字会小于1000000.它说这个数字不到100万 A number with a million digits looks like this 一百万位的数字看起来像这样

591875018734106743196734198673419067843196874398674319687431986743918674319867431986743198674319876341987643198764319876341987643198764319876431987643198763419876431987643198764319876139876...

You can't use scanf to read a number that has a million digits, and you can't store that number in an int . 您不能使用scanf读取具有百万位数的数字,并且您不能将该数字存储在int

The most likely reason for your error to occur is some memory fault. 发生错误的最可能原因是某些内存故障。 Keep in mind that online judges/compilers limit your available memory and if you try to allocate/use more memory than available, you get a runtime error. 请记住,在线评判/编译器限制了您的可用内存,如果您尝试分配/使用的内存超过可用内存,则会出现运行时错误。 This also happens on your machine, but usually you have a lot more memory available for your program than in the case of online judges. 这也发生在你的机器上,但通常你的程序可用的内存比在线评判的情况要多得多。

In your case, you could reduce the memory usage of your program by changing the data type of the num array from int to something like short or even char. 在您的情况下,您可以通过将num数组的数据类型从int更改为short或even char来减少程序的内存使用量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM