关于#c++#的问题,请各位专家解答!

#include
#include
#include
using namespace std;

void pai(int a)
{
    int i, j;
    i = a / 13;           //让i为0~4的数,j为0~12的数;
    j = a % 13;              //i用来判断花色(a/b/c/d),j用来判断数字和字母;
    if (j != 9 && i< 4)      //
    {
        cout << "   ";
    }
    switch (i)
    {
    case 0:
        cout << "a-";
        break;

    case 1:
        cout << "b-";
        break;

    case 2:
        cout << "c-";
        break;

    case 3:
        cout << "d-";
        break;

    case 4:
        cout << "King-";     //特色情况King,只有King1和King2两种情况
        break;

    default:
        break;
    }
    if (i < 4)
    {
        if (j > 0 && j < 10)
            cout << j + 1;
        else if (j == 10)     //将10~12转化为J、Q、K,0转化为A
        {
            cout << "J";
        }
        else if (j == 11)
        {
            cout << "Q";
        }
        else if (j == 12)
        {
            cout << "K";
        }
        else if(j==0)
        {
            cout << "A";
        }
    }
    else
    {
        cout << j + 1;
    }
    cout << "   ";
}


int getline()
{
    int line;
    cout << "-----------------------------------------------------------------------------" << endl;
    cout << "Remember a card,and tell me what line it reside in(1/2/3):";
    cin >> line;
    while (!(line == 1 || line == 2 || line == 3))
    {
        cout << "Input format error,please reenter: ";
        cin >> line;
    }
    return line;
}


int main()
{
    srand((unsigned int)time(NULL));     
    int arr[3][3][3];
    int i = 0, j = 0, n = 0;
    int a, b, c,line1, line2, line3;
    bool judge;

    for(i=0;i<3;i++)
        for(j=0;j<3;j++)
            for (n = 0; n < 3; n++)
            {
                judge = true;
                while (judge)
                {
                    judge = false;
                    arr[i][j][n] = rand() % 27;
                    for (a = 0; a < i - 1; a++)
                        for (b = 0; b < 3; b++)
                            for (c = 0; c < 3; c++)
                                if (arr[a][b][c] == arr[i][j][n])
                                    judge = true;

                    for (b = 0; b < j - 1; b++)
                        for (c = 0; c < 3; c++)
                            if (arr[i][b][c] == arr[i][j][n])
                                judge = true;

                    for (c = 0; c < n - 1; c++)
                        if (arr[i][j][c] == arr[i][j][n])
                            judge = true;
                }
            }
                
    cout << "-----------------------------------------------------------------------------" << endl;
                for (i = 0; i < 3; i++)
                {
                    cout << "Line " << i + 1 << ": ";
                    for (j = 0; j < 3; j++)
                        for(n = 0; n < 3; n++)
                        pai(arr[i][j][n]);
                    cout << endl;
                }
                line1 = getline();

                cout << "-----------------------------------------------------------------------------" << endl;
                for (j = 0; j < 3; j++)
                {
                    cout << "Line " << j + 1 << ": ";
                    for (n = 0; n < 3; n++)
                        for (i = 0; i < 3; i++)
                            pai(arr[i][j][n]);
                    cout << endl;
                }
                line2 = getline();

                cout << "-----------------------------------------------------------------------------" << endl;
                for (n = 0; n < 3; n++)
                {
                    cout << "Line " << n + 1 << ": ";
                    for (i = 0; i < 3; i++)
                        for (j = 0; j < 3; j++)
                            pai(arr[i][j][n]);
                    cout << endl;
                }
                line3 = getline();

                cout << "-----------------------------------------------------------------------------" << endl;
                cout << "Your remembered card is:";
                pai(arr[line1-1][line2-1][line3-1]);       
                cout << endl;
                return 0;

            }

当i=13,结果为1,显然错误,改为 i = (a-1)/13;

另外,如下输出花色:

 system("chcp 437");
    char a = 6;
    cout << a<<" " << (char)3 << " " << (char)4 << " " << (char)5;

img

可以最后添加system("chcp 65001");改回编码