输入的区别导致ac和30%的差别

本题我用C++的cin输入数据只能过30%
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<unordered_map>
using namespace std;
typedef long long ll;
int main()
{
    int n,m,ans=0;
    cin>>n>>m;
    int a[100]={0};
    int b[100][100];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>b[i][j];//--------------------区别
        }
    }
    for(int i=0;i<m;i++)
    {
        int max=b[0][i];
        for(int j=1;j<n;j++)
        {
            if(max<b[j][i])
            {
                max=b[j][i];
            }
        }
        for(int j=0;j<n;j++)
        {
            if(b[j][i]==max)
            {
                a[j]++;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]>0)
            ans++;
    }
    cout<<ans;
    return 0;
}
但是我用c的scanf就可以ac
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<unordered_map>
using namespace std;
typedef long long ll;
int main()
{
    int n,m,ans=0;
    cin>>n>>m;
    int a[100]={0};
    int b[100][100];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            scanf("%1d",&b[i][j]); //--------------------区别
        }
    }
    for(int i=0;i<m;i++)
    {
        int max=b[0][i];
        for(int j=1;j<n;j++)
        {
            if(max<b[j][i])
            {
                max=b[j][i];
            }
        }
        for(int j=0;j<n;j++)
        {
            if(b[j][i]==max)
            {
                a[j]++;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]>0)
            ans++;
    }
    cout<<ans;
    return 0;
}
哪位大佬可以帮我解释一下吗?

全部评论
我没看懂这道题目的意思 有人帮我解释一下不?
1 回复
分享
发布于 2021-04-09 10:10
你这。。。 你用的%d读的是 91728,不是 9
1 回复
分享
发布于 2021-10-08 13:19
滴滴
校招火热招聘中
官网直投
我觉得你可以在每一行输入后面是不是加一个缓冲区getchar()清除缓冲啊
点赞 回复
分享
发布于 2021-04-09 10:10
因为这个两个输入本来就不一样 `cin >> n;` 等价于 `scanf("%d", &n);` 不等价于 `scanf("%1d", &n);`
点赞 回复
分享
发布于 2021-04-09 13:01

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务