This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/DataStructure/Code/ex05/ex5.cpp

147 lines
3 KiB
C++
Raw Permalink Normal View History

2021-10-29 08:51:54 +00:00
#include "vec.h"
#include "list.h"
2021-10-21 16:13:46 +00:00
#include <time.h>
#include <stdio.h>
2021-10-22 11:25:46 +00:00
std::string PU[54] = {
"1A", "1B", "1C", "1D",
"2A", "2B", "2C", "2D",
"3A", "3B", "3C", "3D",
"4A", "4B", "4C", "4D",
"5A", "5B", "5C", "5D",
"6A", "6B", "6C", "6D",
"7A", "7B", "7C", "7D",
"8A", "8B", "8C", "8D",
"9A", "9B", "9C", "9D",
2021-10-22 17:10:00 +00:00
"XA", "XB", "XC", "XD",
2021-10-22 11:25:46 +00:00
"JA", "JB", "JC", "JD",
"QA", "QB", "QC", "QD",
"KA", "KB", "KC", "KD",
2021-10-22 17:10:00 +00:00
"BJ", "RJ"};
2021-10-21 16:13:46 +00:00
int main()
{
2021-10-22 11:25:46 +00:00
int xipai_flag = 0;
2021-10-29 08:51:54 +00:00
printf("生成随机扑克序列\n");
2021-10-21 16:13:46 +00:00
srand(time(NULL));
2021-10-22 11:25:46 +00:00
Vec v(54, 2);
2021-10-22 17:10:00 +00:00
// v.printall();
2021-10-21 16:13:46 +00:00
List l;
2021-10-29 08:51:54 +00:00
printf("开始建立链表\n");
2021-10-21 16:13:46 +00:00
2021-10-22 11:25:46 +00:00
for (int i = 0; i <= 53; i++)
2021-10-21 16:13:46 +00:00
{
l.firstInsert(v.get(i));
2021-10-22 17:10:00 +00:00
std::cout << PU[l[0]] << " ";
if (i % 2 != 0)
printf("\n");
2021-10-22 11:25:46 +00:00
}
Begin:
2021-10-29 08:51:54 +00:00
printf("\n是否重新洗牌?(0/1)");
2021-10-22 11:25:46 +00:00
scanf("%d", &xipai_flag);
if (xipai_flag == 1)
{
v.reorder();
l.clear();
2021-10-29 08:51:54 +00:00
printf("开始建立链表\n");
2021-10-22 11:25:46 +00:00
for (int i = 0; i <= 53; i++)
{
l.firstInsert(v.get(i));
2021-10-22 17:10:00 +00:00
std::cout << PU[l[0]] << " ";
if (i % 2 != 0)
printf("\n");
2021-10-22 11:25:46 +00:00
}
xipai_flag == 0;
goto Begin;
}
2021-10-29 08:51:54 +00:00
printf("开始发牌\n");
2021-10-22 11:25:46 +00:00
List p1, p2, p3;
for (int i = 0; i <= 53; i++)
{
switch (i % 3)
{
case 0:
p1.firstInsert(l[i]);
break;
case 1:
p2.firstInsert(l[i]);
break;
case 2:
p3.firstInsert(l[i]);
break;
}
}
l.clear();
2021-10-22 17:10:00 +00:00
p1.sort();
p2.sort();
p3.sort();
2021-10-22 11:25:46 +00:00
int player = 0, opt = 0;
List *pai;
select:
2021-10-29 08:51:54 +00:00
printf("选择玩家(1/2/3)");
2021-10-22 11:25:46 +00:00
scanf("%d", &player);
switch (player)
{
case 1:
pai = &p1;
break;
case 2:
pai = &p2;
break;
case 3:
pai = &p3;
break;
default:
2021-10-29 08:51:54 +00:00
printf("失败\n");
2021-10-22 11:25:46 +00:00
goto select;
2021-10-21 16:13:46 +00:00
}
2021-10-22 11:25:46 +00:00
while (1)
{
2021-10-27 15:40:44 +00:00
2021-10-29 08:51:54 +00:00
printf("1看牌2出牌3查看牌堆4结束");
2021-10-22 11:25:46 +00:00
scanf("%d", &opt);
switch (opt)
{
case 1:
for (int i = 0; i < (*pai).getSize(); i++)
{
2021-10-22 17:10:00 +00:00
std::cout << i << ": " << PU[(*pai)[i]] << "\n";
2021-10-22 11:25:46 +00:00
}
2021-10-29 08:51:54 +00:00
printf("剩余%d张牌\n", pai->getSize());
2021-10-22 11:25:46 +00:00
break;
case 2:
2021-10-29 08:51:54 +00:00
printf("选择:");
2021-10-22 11:25:46 +00:00
scanf("%d", &opt);
// l.firstInsert((*pai)[opt]);
2021-10-22 17:10:00 +00:00
2021-10-29 08:51:54 +00:00
std::cout << "打出" << PU[l.firstInsert((*pai).remove(opt))];
2021-10-22 17:10:00 +00:00
printf("\n");
2021-10-29 08:51:54 +00:00
printf("剩余%d张牌\n", pai->getSize());
2021-10-22 17:10:00 +00:00
2021-10-22 11:25:46 +00:00
break;
case 3:
2021-10-22 17:10:00 +00:00
for (int i = 0; i < l.getSize(); i++)
{
std::cout << i << ": " << PU[l[i]];
2021-10-22 11:25:46 +00:00
printf("\n");
}
2021-10-27 15:40:44 +00:00
break;
2021-10-21 16:13:46 +00:00
2021-10-22 11:25:46 +00:00
case 4:
goto select;
default:
2021-10-29 08:51:54 +00:00
printf("失败\n");
2021-10-22 11:25:46 +00:00
}
}
2021-10-21 16:13:46 +00:00
return 0;
2021-10-28 12:48:25 +00:00
system("pause");
2021-10-21 16:13:46 +00:00
}