题目链接

A1042

用了大量代码用在了构造纸牌上, 核心代码如下

重点部分

for (int i = 1; i <= 54; i ++ )
    {
        int kk = k - 1;
        int temp = pos[i];
        while (kk -- )
        {
            temp = pos[temp];
        }
        ne[temp] = v[i];
    }

#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
typedef pair<char, int> PII;
int pos[55]; //pos 操作序列,题目输入

char check(int i)//根据i的位置返回字母
{
    if(i >= 1)
    {
        if (i <= 13) return 'S';
        else if (i <= 26) return 'H';
        else if (i <= 39) return 'C';
        else if (i <= 52) return 'D';
        else if (i <= 54) return 'J';
    }
    return ' ';
}

int main()
{
    vector<PII> v;
    vector<PII> ne(55); // 经过操作序列变换后的答案
    //构造纸牌
    v.push_back({' ', 0});
    for (int i = 1, t = 1; i <= 54; i ++)
    {
        v.push_back({check(i), t});
        t ++;
        if(t == 14) t = 1;
    }
    
    int k;
    cin >> k;
    for (int i = 1; i <= 54; i ++ )
        cin >> pos[i];
        
    for (int i = 1; i <= 54; i ++ )
    {
        int kk = k - 1;
        int temp = pos[i];
        while (kk -- )
        {
            temp = pos[temp];
        }
        ne[temp] = v[i];
    }
    for (int i = 1; i <= 54; i ++ )
    {
        if(i == 54) printf("%c%d", ne[i].first, ne[i].second);
        else printf("%c%d ", ne[i].first, ne[i].second);
    }
    return 0;
}