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)    //记录改变方式
    scanf("%d",&next[i]);
  for(int t=0 ; t<n ; ++t)    //改变n次
  {
    for(int i=1 ; i<=N ; ++i)
      end[next[i]]=start[i];
    for(int i=1 ; i<=N ; ++i)
      start[i]=end[i];
  }
  for(int i=1 ; i<=N ; ++i)
  {
    --start[i];      //【warning】不然无法输出13
    if(i==1)
      printf("%c%d",mp[start[i]/13],start[i]%13+1);      //13无法输出
    else
      printf(" %c%d",mp[start[i]/13],start[i]%13+1);
  }
  printf("\n");
  system("pause");
  return 0;
}
时间: 2024-09-28 21:25:25

PAT:1042. Shuffling Machine (20) AC的相关文章

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)

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

PAT:1027. 打印沙漏(20) AC

#include int main() { int n; char xing; scanf("%d %c",&n,&xing); int num=1,i=1; while(1) { num = num + 2 * (i + 2); //一开始就超出,不改变i if(num > n) break; i += 2; } int MAX=i; for(int k=0 ; kPAT:1027. 打印沙漏(20) AC

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

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

【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)-模拟

博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~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 (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 n

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