請不要直接抄寫程式碼! 也請不要直接跳到程式碼部分,除非你已經寫好了,想要參考別人的寫法!

#include <iostream>  
using namespace std;  

int checkA(int *a, int *b, int *guess);  
int checkB(int *a, int *b);  

int main()  
{  
    int answer[4];  
    int answerNumber[11] = {0};  
    for(int i=0;i<4;i++){  
        cin>>answer[i];  
        answerNumber[answer[i]]++;  
    }  

    int counter = 1;  
    int guess[4];  
    while(cin>>guess[0]>>guess[1]>>guess[2]>>guess[3]){  
        int guessNumber[11] = {0};  
        for(int i=0;i<4;i++){  
            guessNumber[guess[i]]++;  
        }  
        int answerA = checkA(answer,guess,guessNumber);  
        int answerB = checkB(answerNumber,guessNumber);  
        cout<<"Case "<<counter<<": "<<answerA<<"A"<<answerB<<"B"<<endl;  
        if ( answerA==4 && answerB==0 )  
            break;  
        else  
            counter++;  

    }  
}  

int checkA(int *a, int *b, int *guess){  
    int A = 0;  
    for(int i=0;i<4;i++){  
        if (a[i]==b[i]){  
            guess[b[i]] = -1;  
            A++;  
        }  
    }  
    return A;  
}  

int checkB(int *a, int *b){  
    int B = 0;  
    for(int i=1;i<10;i++){  
        if ( b[i]==a[i] && b[i]!=0 )  
            B++;  
    }  
    return B;  
}

如果有任何問題,歡迎私訊跟我討論喔!