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 }
时间: 2024-10-25 08:30:39

Shuffling Machine和双向链表的相关文章

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

1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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

pat00-自测5. Shuffling Machine (20)

00-自测5. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 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 "insid

PAT1042.Shuffling Machine

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 A1042. 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

[编程题]Shuffling Machine (洗牌程序)

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

自测-5 Shuffling Machine

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

00-自测5. Shuffling Machine (20)

00-自测5. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 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 "insid

pat1042. Shuffling Machine (20)

1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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