PAT (Advanced Level) 1042. Shuffling Machine (20)

简单题。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;

struct X
{
    char c;
    int num;
}s[60];

int ans[60],p[60],tmp[60];
int n;

void init()
{
    for(int i=1;i<=13;i++) s[i].c=‘S‘,s[i].num=i;
    for(int i=14;i<=26;i++) s[i].c=‘H‘,s[i].num=i-13;
    for(int i=27;i<=39;i++) s[i].c=‘C‘,s[i].num=i-26;
    for(int i=40;i<=52;i++) s[i].c=‘D‘,s[i].num=i-39;
    s[53].c=‘J‘; s[53].num=1;
    s[54].c=‘J‘; s[54].num=2;
}

int main()
{
    init();
    for(int i=1;i<=54;i++) ans[i]=i;

    int k; scanf("%d",&k);
    for(int i=1;i<=54;i++) scanf("%d",&p[i]);

    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=54;j++) tmp[p[j]]=ans[j];
        for(int j=1;j<=54;j++) ans[j]=tmp[j];
    }

    for(int i=1;i<=54;i++)
    {
        printf("%c%d",s[ans[i]].c,s[ans[i]].num);
        if(i<54) printf(" ");
        else printf("\n");
    }
    return 0;
}
时间: 2024-11-07 16:56:39

PAT (Advanced Level) 1042. Shuffling Machine (20)的相关文章

【PAT甲级】1042 Shuffling Machine (20 分)

题意: 输入洗牌次数K(<=20),输入54张牌每次洗入的位置(不是交换的位置),输出洗好的牌. 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;multiset<int>st;int a[57];int card[57],b[57];int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

PAT 1042. Shuffling Machine (20)

1042. Shuffling Machine (20) Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing

1042. Shuffling Machine (20)

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, many cas

1042. Shuffling Machine (20) - sstream实现数字转字符串

题目如下: Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, ma

PAT(A) 1042. Shuffling Machine (20)

The machine shuffles a deck of 54 cards according to a given random order and repeats for a given number of times. It is assumed that the initial status of a card deck is in the following order: S1, S2, ..., S13, H1, H2, ..., H13, C1, C2, ..., C13, D

PAT甲题题解-1042. Shuffling Machine (20)-模拟

博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789205.html特别不喜欢那些随便转载别人的原创文章又不给出链接的所以不准偷偷复制博主的博客噢~ 给出洗牌次数,以及洗牌的序列规则第i个数shuffles[i]表示要将第i张牌移到第shuffles[i]个 很简单,就是shuffle_seq[shuffles[i]]=start_seq[i]; #include <iostream> #include

PAT:1042. Shuffling Machine (20) AC

#include<stdio.h> #include<stdlib.h> const int N=54; int main() { char mp[5]={'S','H','C','D','J'}; int n; scanf("%d",&n); int start[N],end[N],next[N]; for(int i=1 ; i<=N ; ++i) //初始化 start[i]=i; for(int i=1 ; i<=N ; ++i) /

PAT (Advanced Level) 1100. Mars Numbers (20)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; char a[20][6]={ "tret","jan"

1042 Shuffling Machine (20分)

1. 题目 2. 思路 常规题目 3. 注意点 无 4. 代码 #include<cstdio> #include<vector> #include<string> using namespace std; int n; int order[55]; vector<string> cards; void init_cares(){ cards.push_back(""); //占位 for(int i=1;i<=13;i++){ c