#30962: C++ 8934line 答案0A0B 我的0A2B


ahankeu90@gmail.com (Ooscot克特)

學校 : 國立交通大學
編號 : 128771
來源 : [220.143.131.219]
最後登入時間 :
2022-11-25 18:08:34
a291. nAnB problem | From: [220.143.81.23] | 發表日期 : 2022-06-25 21:03

如題,已經試過很多組大家提供的測資都沒問題,唯獨這個,不知道程式碼哪裡出問題。

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ans[5];
    int n,Try[5],A=0,B=0;

    while(scanf("%d %d %d %d",&ans[1],&ans[2],&ans[3],&ans[4])!=EOF){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cin>>n;
    for(int i=1; i<=n; i++)
    {
        A=0;
        B=0;
        bool check[5][3];
        memset(check,0,sizeof(check));
        for(int j=1; j<=4; j++)
        {
            ios_base::sync_with_stdio(false);
            cin.tie(0);
            cin>>Try[j];
        }

        for(int a=1; a<=4; a++)
        {
                if(ans[a]==Try[a]){
                    A++;
                    check[a][1]=true;
                    check[a][2]=true;

                }
        }
        for(int a=1;a<=4;a++){
            for(int b=1;b<=4;b++){
                if(check[a][1]==true)
                    break;
                if(check[b][2]==true)
                continue;
                if(ans[a]==Try[b]){
                    B++;
                    check[b][2]=true;
                    break;

 

                }

            }    }printf("%dA%dB\n",A,B);
    }

    }
    return 0;
}

 
#31074: Re: C++ 8934line 答案0A0B 我的0A2B


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
a291. nAnB problem | From: [39.9.78.186] | 發表日期 : 2022-07-09 21:36


        ios_base::sync_with_stdio(false);


io問題,你用了sync_with_stdio(false)就不能再混用scanf, printf這種stdio的函式

 
ZeroJudge Forum