[英]Not being able to enter input during runtime
当我用输入编译代码时,它工作正常。 但是当我想用用户输入运行它时,它只是不接受输入。 它没有给出任何错误。
// kefaa and first steps
// 2 2 1 3 4 1
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, a[n], counter=0, maxIncr=0;
cin >> n;
cin.sync();
for(int i = 0; i < n; ++i){
cin >> a[i];
}
for(int i=0; i < n-1; ++i){
if (a[i] <= a[i+1]){
counter += 1;
if(maxIncr<counter)
maxIncr=counter;
}else{
counter=1;
}
}
cout << maxIncr;
return 0;
}
首先阅读有关您的包含以及为什么我们不包含这样的内容。
其次,如果您希望程序运行:
int n;
cin >> n;
int a[n], counter=0, maxIncr=0;
你有什么就像@UnholySheep 写给你的一样,你在 n 还没有被赋值时初始化 a[n] 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.