C++ 库特<<&引用&“;正在改变我的答案,用C++;

C++ 库特<<&引用&“;正在改变我的答案,用C++;,c++,cout,C++,Cout,我试图解决一些ds问题,所有的事情都很好,算法正确,但答案正确(错误),然后调试时,我放cout检查错误发生在哪里,当我放cout时,答案是正确的,但没有它,答案是错误的 另外,不同的在线编译器正在显示正确的答案 没有cout和Is 1:7:4(错误的ans) 答案是1:7:3(正确答案) 输入是 2 9 1 0 1 1 0 1 1 1 1 0 0 1 0 1 0 0 1 #include <bits/stdc++.h> using namespace std; int ma

我试图解决一些ds问题,所有的事情都很好,算法正确,但答案正确(错误),然后调试时,我放cout检查错误发生在哪里,当我放cout时,答案是正确的,但没有它,答案是错误的 另外,不同的在线编译器正在显示正确的答案

没有cout和Is 1:7:4(错误的ans) 答案是1:7:3(正确答案) 输入是 2 9 1 0 1 1 0 1 1 1 1 0 0 1 0 1 0 0 1

 #include <bits/stdc++.h>
 using namespace std; 
 int main()
 {
int n,m;
int a,b;
int ans=0; 
int ansij=INT_MAX;
  cin>>n>>m;
  int arr[n+10][m+10]; 
  for(int i=0;i<n;i++)
  {
  { for(int j=0;j<m;j++) 
    cin>>arr[i][j];
   }
  }
  
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++) 
  { if(i==0&&j==0)
    continue; 
    int score=0;
    if(arr[i][j]==1)
    { //cout<<arr[i][j]<<endl ;
      //1
     if(arr[i+1][j]==1)      
     score++;
     //2
     
     if(arr[i][j+1]==1)
      score++;
      //3
      if(arr[i-1][j]==1)      
     score++;
     //4
     if(arr[i][j-1]==1)
      score++;
      //5
      if(arr[i+1][j+1]==1)      
     score++;
     //6
     if(arr[i+1][j-1]==1)
      score++;
      //7
    if(arr[i-1][j+1]==1)      
     score++;
     //8
     if(arr[i-1][j-1]==1)
      score++;
    }
//cout<<"";
//cout<<"score of i and j is ("<<i+1<<","<<j+1<<") "<<score<<endl;

if(ans<score)
{ ans=score; 
  ansij=i+j;
  a=i;
  b=j;
//cout<<" answer update from gretest"<<endl;
    
}
else if(ans==score)
{ if(ansij>=(i+j))
{ ans=score;
  ansij=i+j;
  a=i;
  b=j;
//cout<<" answer update from qual"<<endl;
}
}
//cout<<" answer in i j is"<<ans<<endl;
}
}  
cout<<a+1<<":"<<b+1<<":"<<ans;   
  
  return 0;
}
#包括
使用名称空间std;
int main()
{
int n,m;
INTA,b;
int ans=0;
int ansij=int_MAX;
cin>>n>>m;
国际无线电频率[n+10][m+10];
对于(int i=0;iarr[i][j];
}
}
对于(inti=0;i“cout”不是问题

我已经用给定的值初始化了一个矩阵,并从键盘上读取了值
n=2
m=9

intarr[n+10][m+10]{1,0,1,1,0,1,1,1,0,0,0,1,0,0,1};
而且不能打印出
1:7:3
(你说的,应该是正确的答案)


<>这意味着你的问题是读矩阵。< /p>请正确地缩进你的代码。我们应该如何从这个混乱的混乱中得到任何意义?标准C++没有。使用它。<代码> int ARR [n+1] [M+3];< /C> >这不是合法的C++。看起来你从一个“在线法官”中得到这个问题。如果你知道你使用的语言足够好,而不是把语言的基本知识弄错,或者用奇怪的方式使用语言。这些网站不是用来教C++的。至于你的问题(除了尝试使用“竞争”网站来学习),你还需要使用未初始化的数组部分。