为什么会出现输入输不尽的情况

问题

img

img

img

代码

#include<iostream>
#include<algorithm>

using namespace std;

const int N=110;

int tou[N][N];
int ban[N][N];
int a,b;

int main()
{
    int n,m;
    cin>>n>>m;
    
    for(int i=1;i<=n;i++)//输入插排 
    {
        for(int j=1;j<=m;j++)
        {
            cin>>ban[i][j];
        }
        
        cout<<endl;
    }
    
    int r,c;
    cin>>r>>c;
            
    for(int i=1;i<=r;i++)//输入插头 
        for(int j=1;j<=c;j++)
            cin>>tou[i][j];
            
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            if(i+r-1>n||j+c-1>m)
                continue;
                
            if(tou[1][1]<=ban[i][j])
            {
                bool tr=true;
                for(int s=1;s<=r;s++)//检查每个插头的数是否符合插板 
                {
                    for(int t=1;t<=c;t++)
                    {
                        if(tou[s][t]>ban[i+s-1][j+t-1])
                        {
                            tr=false;
                            break;
                         }
                    }
                    
                    if(!tr)
                        break;
                }
                
                if(tr)
                {
                    if(i<a)
                    {
                        a=i;
                        b=j;
                    }
                    
                    if(i==a&&j<b)
                    {
                        b=j;
                    }
                }
            }
        }
        
    if(a==0&&b==0) 
          printf("NO");
    else    
        cout<<a<<" "<<b<<endl;
    
    return 0;
}

疑问
以上面的样例为例,结果输入的时候,输完了之后,光标还在等着,为什么呢?

img

就卡在了上面这样

输入数字是读取到空格或者回车结束的,所以0110读取到的数字是110,改成这样

#include<iostream>
#include<algorithm>
 
using namespace std;
 
const int N=110;
 
int tou[N][N];
int ban[N][N];
int a,b;
 
int main()
{
    int n,m;
    cin>>n>>m;
    
    char ch;
    for(int i=1;i<=n;i++)//输入插排 
    {
        for(int j=1;j<=m;j++)
        {
            cin>>ch;
            ban[i][j] = ch - '0';
        }
    }
    
    int r,c;
    cin>>r>>c;
            
    for(int i=1;i<=r;i++)//输入插头 
        for(int j=1;j<=c;j++){
            cin>>ch;
            tou[i][j] = ch - '0';
            
        }
            
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            if(i+r-1>n||j+c-1>m)
                continue;
                
            if(tou[1][1]<=ban[i][j])
            {
                bool tr=true;
                for(int s=1;s<=r;s++)//检查每个插头的数是否符合插板 
                {
                    for(int t=1;t<=c;t++)
                    {
                        if(tou[s][t]>ban[i+s-1][j+t-1])
                        {
                            tr=false;
                            break;
                         }
                    }
                    
                    if(!tr)
                        break;
                }
                
                if(tr)
                {
                    if(i<a)
                    {
                        a=i;
                        b=j;
                    }
                    
                    if(i==a&&j<b)
                    {
                        b=j;
                    }
                }
            }
        }
        
    if(a==0&&b==0) 
          printf("NO");
    else    
        cout<<a<<" "<<b<<endl;
    
    return 0;
}