Shuffling Machine和双向链表
Posted LeoSanford
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shuffling Machine和双向链表相关的知识,希望对你有一定的参考价值。
1. 双向链表
https://github.com/BodhiXing/Data_Structure
2. Shuffling Machine
https://pta.patest.cn/pta/test/17/exam/4/question/264
思路:
代码:
1 #include <iostream> 2 using namespace std; 3 4 #define MAXCARD 54 5 6 string int2str(int x) 7 { 8 char ch[4]; 9 sprintf(ch,"%d",x); 10 return ch; 11 } 12 13 void Shuffling(string* str,const int* const ord ) 14 { 15 int i; 16 string tmp[MAXCARD]; 17 18 for(i=0;i<MAXCARD;i++) 19 tmp[ord[i]] = str[i]; 20 for(i=0;i<MAXCARD;i++) 21 str[i] = tmp[i]; 22 } 23 int main() 24 { 25 int num,i; 26 string card[MAXCARD]; 27 int order[MAXCARD]; 28 cin>>num; 29 30 string str; 31 for(i=0;i<13;i++) 32 { 33 str = int2str(i+1); 34 card[i] = "S"+str; 35 card[i+13] = "H"+str; 36 card[i+26] = "C"+str; 37 card[i+39] = "D"+str; 38 } 39 card[52] = "J1"; 40 card[53] = "J2"; 41 42 for(i=0;i<MAXCARD;i++) 43 { 44 cin>>order[i]; 45 order[i]--; //和数组下标一致 0...53 46 } 47 48 for(i=0;i<num;i++) 49 Shuffling(card,order); 50 51 for(i=0;i<MAXCARD-1;i++) 52 cout<<card[i]<<" "; 53 cout<<card[i]; 54 55 return 0; 56 }
以上是关于Shuffling Machine和双向链表的主要内容,如果未能解决你的问题,请参考以下文章
PAT-1042. Shuffling Machine (20)