TYVJ1424-Divination DIY

The topic is a bit long, and it is best to take a piece of A4 paper and write it out for the sample.

It can be found that the program must not be in an infinite loop, because each kind of card is 4 cards, and the condition of the infinite loop is that a certain card has 5 cards and then you take it and put it in. If it is written in an infinite loop, it is written incorrectly.

A few points may be worth noting:

1. A card is 1, don't write A as 11, and then find out what happened to a total of 56 cards. .

2. It's better to open a variable nxt to record the next card that you get. It is easy to make mistakes and not find out if you only use one variable to record the current card.

3. The number of pairs in the final count is how many cards have been turned over 4 times in total

Although I wrote it for a morning, but fortunately it was 1A and contributed my own 1S~

code show as below:

#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;

deque<char> que[14];
char now,nxt;
int vis[233][233],k,hath[233];
void print()
{
    for(int i=1;i<=13;++i){
        for(int j=0;j<4;++j)
            cout<<que[i][j]<<' ';
        cout<<endl;
    }
    cout<<"******"<<endl;
}
int  main() {
    for(int i=1; i<=13; ++i)
        for(int j=0; j<4; ++j) {
            char x;
            cin>>x;
            que[i].push_back(x);
        }
    while(k<4) {
        now=que[13][k];
        nxt='^';
        while(now!='K') {
            //vis[now-'0'][now-'0']=1;
            //cout<<now<<' '<<nxt<<endl;
            switch(now) {
            case 'A':
                que[1].push_front(now);
                hath[1]++;
                nxt = que [ 1 ] .back ();
                que[1].pop_back();
                break;
            case 'J':
                que[11].push_front(now);
                hath[11]++;
                nxt = que [ 11 ] .back ();
                que[11].pop_back();
                break;
            case 'Q':
                que[12].push_front(now);
                hath[12]++;
                nxt = que [ 12 ] .back ();
                que[12].pop_back();
                break;
            
            case '0':
                que[10].push_front(now);
                hath[10]++;
                nxt = que [ 10 ] .back ();
                que[10].pop_back();
                break;
            default:
                que[now-'0'].push_front(now);
                hath[now-'0']++;
                nxt=que[now-'0'].back();
                que[now-'0'].pop_back();
                break;
            }
            now=nxt;
        }
        //cout<<"***"<<k+1<<endl;
        //print();
        ++k;
    }
    int ans=0;
    for(int i=1;i<=12;++i)
        ans+=hath[i]==4;
    cout<<ans<<endl;
    
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325250090&siteId=291194637