c++ - 我在下面的代码中收到错误 “Output Limit Exceeded”

标签 c++ error-handling

这是我为查找小于或等于给定编号的跳跃数而编写的代码。它显示错误“超出输出限制”

int main() {
int t;
cin>>t;
while(t--)
{
    long long int n ,rem,temp;
    cin>>n ;
    for(int i=0 ; i<=n ; ++i)
    {
        if(i<=10)
        cout<<i<<" ";
        else
        {   
            temp=i;
           do                   
            {
               rem=i%10;
               i/=10;
            }while(abs(rem-i%10)==1);
            if(i==0)
            {
                cout<<temp<<" "; // printing jumping no.s
            }
        }
    }
    cout<<"\n";
}
return 0;

}

最佳答案

您在do-while循环中将i除以10!当我达到11时,它将除以10,然后在主for循环的下一次迭代中,您将获得非常低的i值,回到之前的值。你的循环永远不会结束。

关于c++ - 我在下面的代码中收到错误 “Output Limit Exceeded”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55045013/

相关文章:

c++ - 在 C++ Builder 中编译 Boost 库时的警告

c++ - 使用 CMake、Clang 和 Ninja 在 Windows 上构建 c++ 项目

javascript - 在IE11上显示黑屏的Create-React-App。错误: SCRIPT5009: 'WebSocket' is undefined and SCRIPT5009: 'Promise' is undefined

Pythonic 异常处理 : only catching specific errno

c - 这个函数的错误处理有问题吗?

vba - 组合框的无效属性值

node.js - Node 7 : How to Show the Correct Stack Trace in Async Mongoose Promises

c++ - 未定义的“函数引用”

c++ - C rand() 并不是真正随机的

c++ - GCC - 如何仅使用 FLV1(又名 H.263)、MP3(格式和编解码器)和 FLV(容器格式)编译 FFMpeg?