该程序无法显示第二个迭代的输出

The program is not able to show the output from second iteration onwards

本文关键字:迭代 输出 第二个 显示 程序      更新时间:2023-10-16
for(int i=0;i<T;i++)   // t test cases
{
    int flag=0;        //flag variable to check the output
    char A[3][3];
    for(int j=0;j<3;j++)        //Taking
        for(int k=0;k<3;k++)     //Input
           cin>>A[j][k];          //in a character Array
    //checking for letter 'l' in the character array and if other l's  also exist or not
    for(int j=0;j<2;j++)
      for(int k=0;k<2;k++)
    {
        if(A[j][k]=='l')
        {
            if(A[j+1][k]=='l' && A[j+1][k+1]=='l')
                flag++;
        }
    }
     if(flag>0)
            cout<<"yes"<<endl;
}
return 0;

}

这是我的代码,问题是在3*3个字符数组中检查是否存在类似
的模式l
ll

它适用于第一次迭代或第一个测试用例,但并未显示第二个迭代。

它可以正常工作,您可以在此处看到:在线gdb.com/r1vcs-fxn。

您没有看到结果,因为您没有"否" cout。

链接中的代码,以防万一停止工作:

#include <iostream>
using namespace std;
int main() {
    const int T = 3;
    cout << "T: " << T << endl;
    for(int i=0;i<T;i++)   // t test cases
    {
        int flag=0;        //flag variable to check the output
        char A[3][3];
        for(int j=0;j<3;j++)        //Taking
            for(int k=0;k<3;k++)     //Input
                cin>>A[j][k];          //in a character Array
        //checking for letter 'l' in the character array and if other l's  also exist or not
        for(int j=0;j<2;j++)
            for(int k=0;k<2;k++) {
                if(A[j][k]=='l') {
                    if(A[j+1][k]=='l' && A[j+1][k+1]=='l')
                        flag++;
                }
            }
        cout << "Flags: " << flag << endl;
        if(flag>0)
            cout<<"yes"<<endl;
        else
            cout << "nope" << endl;
    }
    return 0;
}