编译命令与编码更改

This commit is contained in:
iridiumR 2021-10-29 16:51:54 +08:00
parent 6ecaa0a7d8
commit ff6c8fba01
8 changed files with 92 additions and 92 deletions

View file

@ -4,15 +4,15 @@
#include <time.h> #include <time.h>
int LENGTH; int LENGTH;
//数组长度 //数组长度
int RANDOM = 0; int RANDOM = 0;
//是否随机生成数组 //是否随机生成数组
int MODE = 0; int MODE = 0;
//1: 迭代 //1: 迭代
//2: 递归 //2: 递归
// #define OUTPUT // #define OUTPUT
//是否输出 //是否输出
int *a; int *a;
@ -87,18 +87,18 @@ void init()
int main() int main()
{ {
Begin: Begin:
printf("是否随机生成数组(0/1):"); printf("是否随机生成数组(0/1):");
scanf("%d", &RANDOM); scanf("%d", &RANDOM);
printf("输入数组长度:"); printf("输入数组长度:");
scanf("%d", &LENGTH); scanf("%d", &LENGTH);
printf("选择模式:1.迭代 2.递归"); printf("选择模式:1.迭代 2.递归");
scanf("%d", &MODE); scanf("%d", &MODE);
if ((MODE <= 0) || (MODE >= 3)) if ((MODE <= 0) || (MODE >= 3))
{ {
printf("错误输入\n"); printf("错误输入\n");
goto Begin; goto Begin;
} }
@ -122,7 +122,7 @@ Begin:
printf("%d \n", a[i]); printf("%d \n", a[i]);
#endif #endif
printf("运算时间: %.4f 秒\n", ((double)(end_t - start_t) / CLOCKS_PER_SEC)); printf("运算时间: %.4f 秒\n", ((double)(end_t - start_t) / CLOCKS_PER_SEC));
system("pause"); system("pause");
goto Begin; goto Begin;

View file

@ -162,40 +162,40 @@ int main()
int temp[10] = {0}; int temp[10] = {0};
int flag; int flag;
printf("初始化,输出数组\n"); printf("初始化,输出数组\n");
v.printall(); v.printall();
while (1) while (1)
{ {
printf("选择操作:1.插入 2.删除 3.查找\n"); printf("选择操作:1.插入 2.删除 3.查找\n");
scanf("%d", &flag); scanf("%d", &flag);
switch (flag) switch (flag)
{ {
case 1: case 1:
printf("输入秩与待插入数值\n"); printf("输入秩与待插入数值\n");
scanf("%d %d", &temp[0], &temp[1]); scanf("%d %d", &temp[0], &temp[1]);
(v.insert(temp[0], temp[1])) ? (printf("非法输入\n")) : (printf("输出数组\n")); (v.insert(temp[0], temp[1])) ? (printf("非法输入\n")) : (printf("输出数组\n"));
v.printall(); v.printall();
break; break;
case 2: case 2:
printf("输入秩与待删除个数\n"); printf("输入秩与待删除个数\n");
scanf("%d %d", &temp[0], &temp[1]); scanf("%d %d", &temp[0], &temp[1]);
(v.del(temp[0], temp[1])) ? (printf("非法输入\n")) : (printf("输出数组\n")); (v.del(temp[0], temp[1])) ? (printf("非法输入\n")) : (printf("输出数组\n"));
v.printall(); v.printall();
break; break;
case 3: case 3:
printf("输入要查找的数值\n"); printf("输入要查找的数值\n");
scanf("%d", &temp[0]); scanf("%d", &temp[0]);
temp[2] = v.find(temp[0]); temp[2] = v.find(temp[0]);
(temp[2] == -1) ? (printf("无此元素\n")) : (printf("秩为%d \n", temp[2])); (temp[2] == -1) ? (printf("无此元素\n")) : (printf("秩为%d \n", temp[2]));
break; break;
default: default:
printf("返回菜单\n"); printf("返回菜单\n");
} }
flag = 0; flag = 0;

View file

@ -1,6 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "vec.cpp" #include "vec.h"
int main() int main()
{ {
int flag = 0; int flag = 0;
@ -8,50 +8,50 @@ int main()
srand(time(NULL)); srand(time(NULL));
int len; int len;
printf("输入生成数量\n"); printf("输入生成数量\n");
scanf("%d", &len); scanf("%d", &len);
Vec v(len); Vec v(len);
v.printall(); v.printall();
system("pause"); system("pause");
printf("排序:秩为%d\n",v.getused()); printf("排序:秩为%d\n",v.getused());
// v.bubbleSort(); // v.bubbleSort();
v.mergeSort(0,v.getused()); v.mergeSort(0,v.getused());
v.printall(); v.printall();
while (1) while (1)
{ {
printf("选择操作:1.插入 2.删除 3.统计 4.退出\n"); printf("选择操作:1.插入 2.删除 3.统计 4.退出\n");
scanf("%d", &flag); scanf("%d", &flag);
switch (flag) switch (flag)
{ {
case 1: case 1:
printf("输入待插入数值\n"); printf("输入待插入数值\n");
scanf("%d", &temp[0]); scanf("%d", &temp[0]);
printf("插入秩为%d处\n",v.search(temp[0]) + 1); printf("插入秩为%d处\n",v.search(temp[0]) + 1);
(v.insert(v.search(temp[0]) + 1, temp[0]) != -1) ? (printf("输出数组\n")) : (printf("无此元素或超出范围\n")); (v.insert(v.search(temp[0]) + 1, temp[0]) != -1) ? (printf("输出数组\n")) : (printf("无此元素或超出范围\n"));
v.printall(); v.printall();
break; break;
case 2: case 2:
printf("输入待删除元素\n"); printf("输入待删除元素\n");
scanf("%d", &temp[0]); scanf("%d", &temp[0]);
(v.remove_sorted(temp[0]) != -1) ? (printf("输出数组\n")) : (printf("无此元素或超出范围\n")); (v.remove_sorted(temp[0]) != -1) ? (printf("输出数组\n")) : (printf("无此元素或超出范围\n"));
v.printall(); v.printall();
break; break;
case 3: case 3:
printf("输入统计的数值\n"); printf("输入统计的数值\n");
scanf("%d", &temp[0]); scanf("%d", &temp[0]);
temp[1] = v.count(temp[0]); temp[1] = v.count(temp[0]);
(temp[1] != -1) ? (printf("一共%d个\n", temp[1])) : (printf("无此元素或超出范围\n")); (temp[1] != -1) ? (printf("一共%d个\n", temp[1])) : (printf("无此元素或超出范围\n"));
break; break;
case 4: case 4:
return 0; return 0;
default: default:
printf("返回菜单\n"); printf("返回菜单\n");
} }
flag = 0; flag = 0;
} }

View file

@ -59,7 +59,7 @@ void Vec::shrink()
delete[] _v; delete[] _v;
_v = p; _v = p;
} }
//位置 数值 //位置 数值
int Vec::insert(int locate, int value) int Vec::insert(int locate, int value)
{ {
if (locate == _used + 1) if (locate == _used + 1)
@ -84,7 +84,7 @@ int Vec::insert(int locate, int value)
return 0; return 0;
} }
//位置 删除个数 //位置 删除个数
int Vec::remove(int locate, int value) int Vec::remove(int locate, int value)
{ {
@ -101,7 +101,7 @@ int Vec::remove(int locate, int value)
return value; return value;
} }
//删除某一元素 //删除某一元素
int Vec::remove_sorted(int value) int Vec::remove_sorted(int value)
{ {
int j, i; int j, i;

View file

@ -1,6 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "vec.cpp" #include "vec.h"
int main() int main()
{ {
int flag = 0; int flag = 0;

View file

@ -1,5 +1,5 @@
#include "vec.cpp" #include "vec.h"
#include "list.cpp" #include "list.h"
#include <time.h> #include <time.h>
#include <stdio.h> #include <stdio.h>
std::string PU[54] = { std::string PU[54] = {
@ -22,14 +22,14 @@ int main()
{ {
int xipai_flag = 0; int xipai_flag = 0;
printf("生成随机扑克序列\n"); printf("生成随机扑克序列\n");
srand(time(NULL)); srand(time(NULL));
Vec v(54, 2); Vec v(54, 2);
// v.printall(); // v.printall();
List l; List l;
printf("开始建立链表\n"); printf("开始建立链表\n");
for (int i = 0; i <= 53; i++) for (int i = 0; i <= 53; i++)
{ {
@ -40,7 +40,7 @@ int main()
} }
Begin: Begin:
printf("\n是否重新洗牌?(0/1)"); printf("\n是否重新洗牌?(0/1)");
scanf("%d", &xipai_flag); scanf("%d", &xipai_flag);
if (xipai_flag == 1) if (xipai_flag == 1)
@ -49,7 +49,7 @@ Begin:
l.clear(); l.clear();
printf("开始建立链表\n"); printf("开始建立链表\n");
for (int i = 0; i <= 53; i++) for (int i = 0; i <= 53; i++)
{ {
@ -61,7 +61,7 @@ Begin:
xipai_flag == 0; xipai_flag == 0;
goto Begin; goto Begin;
} }
printf("开始发牌\n"); printf("开始发牌\n");
List p1, p2, p3; List p1, p2, p3;
for (int i = 0; i <= 53; i++) for (int i = 0; i <= 53; i++)
{ {
@ -85,7 +85,7 @@ Begin:
int player = 0, opt = 0; int player = 0, opt = 0;
List *pai; List *pai;
select: select:
printf("选择玩家(1/2/3)"); printf("选择玩家(1/2/3)");
scanf("%d", &player); scanf("%d", &player);
switch (player) switch (player)
{ {
@ -99,13 +99,13 @@ select:
pai = &p3; pai = &p3;
break; break;
default: default:
printf("失败\n"); printf("失败\n");
goto select; goto select;
} }
while (1) while (1)
{ {
printf("1看牌2出牌3查看牌堆4结束"); printf("1看牌2出牌3查看牌堆4结束");
scanf("%d", &opt); scanf("%d", &opt);
switch (opt) switch (opt)
{ {
@ -114,16 +114,16 @@ select:
{ {
std::cout << i << ": " << PU[(*pai)[i]] << "\n"; std::cout << i << ": " << PU[(*pai)[i]] << "\n";
} }
printf("剩余%d张牌\n", pai->getSize()); printf("剩余%d张牌\n", pai->getSize());
break; break;
case 2: case 2:
printf("选择:"); printf("选择:");
scanf("%d", &opt); scanf("%d", &opt);
// l.firstInsert((*pai)[opt]); // l.firstInsert((*pai)[opt]);
std::cout << "打出" << PU[l.firstInsert((*pai).remove(opt))]; std::cout << "打出" << PU[l.firstInsert((*pai).remove(opt))];
printf("\n"); printf("\n");
printf("剩余%d张牌\n", pai->getSize()); printf("剩余%d张牌\n", pai->getSize());
break; break;
case 3: case 3:
@ -138,7 +138,7 @@ select:
goto select; goto select;
default: default:
printf("失败\n"); printf("失败\n");
} }
} }
return 0; return 0;

View file

@ -68,7 +68,7 @@ void Vec::shrink()
delete[] _v; delete[] _v;
_v = p; _v = p;
} }
//位置 数值 //位置 数值
int Vec::insert(int locate, int value) int Vec::insert(int locate, int value)
{ {
if (locate == _used + 1) if (locate == _used + 1)
@ -93,7 +93,7 @@ int Vec::insert(int locate, int value)
return 0; return 0;
} }
//位置 删除个数 //位置 删除个数
int Vec::remove(int locate, int value) int Vec::remove(int locate, int value)
{ {
@ -110,7 +110,7 @@ int Vec::remove(int locate, int value)
return value; return value;
} }
//删除某一元素 //删除某一元素
int Vec::remove_sorted(int value) int Vec::remove_sorted(int value)
{ {
int j, i; int j, i;

View file

@ -25,13 +25,13 @@ int main()
{ {
Score s(3); Score s(3);
int xipai_flag = 0; int xipai_flag = 0;
printf("生成随机扑克序列\n"); printf("生成随机扑克序列\n");
srand(time(NULL)); srand(time(NULL));
Vec v(54, 2); Vec v(54, 2);
List l; List l;
printf("开始建立链表\n"); printf("开始建立链表\n");
for (int i = 0; i <= 53; i++) for (int i = 0; i <= 53; i++)
{ {
@ -42,7 +42,7 @@ int main()
} }
Begin: Begin:
printf("\n是否重新洗牌?(0/1)"); printf("\n是否重新洗牌?(0/1)");
scanf("%d", &xipai_flag); scanf("%d", &xipai_flag);
if (xipai_flag == 1) if (xipai_flag == 1)
@ -51,7 +51,7 @@ Begin:
l.clear(); l.clear();
printf("===============开始建立链表===============\n"); printf("===============开始建立链表===============\n");
for (int i = 0; i <= 53; i++) for (int i = 0; i <= 53; i++)
{ {
@ -63,7 +63,7 @@ Begin:
xipai_flag == 0; xipai_flag == 0;
goto Begin; goto Begin;
} }
printf("================开始发牌================\n"); printf("================开始发牌================\n");
List p1, p2, p3; List p1, p2, p3;
for (int i = 0; i <= 53; i++) for (int i = 0; i <= 53; i++)
{ {
@ -80,7 +80,7 @@ Begin:
break; break;
} }
} }
printf("你手中的牌:\n"); printf("你手中的牌:\n");
for (int i = 0; i < p1.getSize(); i++) for (int i = 0; i < p1.getSize(); i++)
{ {
std::cout << i << ": " << PU[(p1)[i]] << "\n"; std::cout << i << ": " << PU[(p1)[i]] << "\n";
@ -94,23 +94,23 @@ Begin:
int pass_num = 0; int pass_num = 0;
int round = 1; int round = 1;
int finish_num = 0; int finish_num = 0;
printf("理牌完成,选择你的操作:\n"); printf("理牌完成,选择你的操作:\n");
while (finish_num < 2 && round < 54) while (finish_num < 2 && round < 54)
{ {
if (pass_num > 3 - finish_num) if (pass_num > 3 - finish_num)
pass_num = 3 - finish_num; pass_num = 3 - finish_num;
printf("+++++===========================+++++\n 轮次%d \n+++++===========================+++++\n", round); printf("+++++===========================+++++\n 轮次%d \n+++++===========================+++++\n", round);
if (p1.getSize()) if (p1.getSize())
{ {
printf("你手中的牌:\n"); printf("你手中的牌:\n");
for (int i = 0; i < p1.getSize(); i++) for (int i = 0; i < p1.getSize(); i++)
{ {
std::cout << i << ": " << PU[(p1)[i]] << "\n"; std::cout << i << ": " << PU[(p1)[i]] << "\n";
} }
printf("剩余%d张牌\n", p1.getSize()); printf("剩余%d张牌\n", p1.getSize());
// if (l[0] > p1[p1.getSize() - 1]) // if (l[0] > p1[p1.getSize() - 1])
// { // {
@ -119,31 +119,31 @@ Begin:
// pass_num = 0; // pass_num = 0;
// goto A; // goto A;
// } // }
// printf("无法出牌,已自动跳过\n"); // printf("无法出牌,已自动跳过\n");
// } // }
A: A:
printf("0出牌1查看牌堆2跳过"); printf("0出牌1查看牌堆2跳过");
scanf("%d", &opt); scanf("%d", &opt);
switch (opt) switch (opt)
{ {
case 0: case 0:
printf("选择:"); printf("选择:");
scanf("%d", &opt); scanf("%d", &opt);
if (opt >= p1.getSize() || (p1[opt] < l[0]&&pass_num!=2)) if (opt >= p1.getSize() || (p1[opt] < l[0]&&pass_num!=2))
{ {
printf("错误输入\n"); printf("错误输入\n");
goto A; goto A;
} }
std::cout << "打出" << PU[l.firstInsert((p1).remove(opt))]; std::cout << "打出" << PU[l.firstInsert((p1).remove(opt))];
if (p1.getSize() == 0) if (p1.getSize() == 0)
{ {
s.finish(0); s.finish(0);
printf(",玩家A出完所有牌\n"); printf(",玩家A出完所有牌\n");
finish_num++; finish_num++;
pass_num = 0; pass_num = 0;
} }
else else
printf(",剩余%d张牌\n", p1.getSize()); printf(",剩余%d张牌\n", p1.getSize());
pass_num=0; pass_num=0;
break; break;
@ -160,27 +160,27 @@ Begin:
goto B; goto B;
default: default:
printf("错误输入\n"); printf("错误输入\n");
goto A; goto A;
} }
} }
else else
printf("玩家A轮空\n"); printf("玩家A轮空\n");
B: B:
if (p2.getSize()) if (p2.getSize())
{ {
printf("--------------------\n"); printf("--------------------\n");
printf("B玩家"); printf("B玩家");
if (pass_num == 2 - finish_num) if (pass_num == 2 - finish_num)
{ {
std::cout << "打出" << PU[l.firstInsert((p2).remove(0))]; std::cout << "打出" << PU[l.firstInsert((p2).remove(0))];
printf(",剩余%d张牌\n", p2.getSize()); printf(",剩余%d张牌\n", p2.getSize());
pass_num = 0; pass_num = 0;
} }
else if (l[0] > p2[p2.getSize() - 1]) else if (l[0] > p2[p2.getSize() - 1])
{ {
printf("无牌可出,跳过\n"); printf("无牌可出,跳过\n");
pass_num++; pass_num++;
} }
else else
@ -189,9 +189,9 @@ Begin:
if (l[0] < p2[i]) if (l[0] < p2[i])
{ {
std::cout << "打出" << PU[l.firstInsert((p2).remove(i))]; std::cout << "打出" << PU[l.firstInsert((p2).remove(i))];
printf(",剩余%d张牌\n", p2.getSize()); printf(",剩余%d张牌\n", p2.getSize());
pass_num = 0; pass_num = 0;
break; break;
} }
@ -199,28 +199,28 @@ Begin:
if (p2.getSize() == 0) if (p2.getSize() == 0)
{ {
s.finish(1); s.finish(1);
printf("玩家B出完所有牌\n"); printf("玩家B出完所有牌\n");
finish_num++; finish_num++;
pass_num = 0; pass_num = 0;
} }
} }
else else
printf("玩家B轮空\n"); printf("玩家B轮空\n");
C: C:
if (p3.getSize()) if (p3.getSize())
{ {
printf("--------------------\n"); printf("--------------------\n");
printf("C玩家"); printf("C玩家");
if (pass_num == 2 - finish_num) if (pass_num == 2 - finish_num)
{ {
std::cout << "打出" << PU[l.firstInsert((p3).remove(0))]; std::cout << "打出" << PU[l.firstInsert((p3).remove(0))];
printf(",剩余%d张牌\n", p3.getSize()); printf(",剩余%d张牌\n", p3.getSize());
pass_num = 0; pass_num = 0;
} }
else if (l[0] > p3[p3.getSize() - 1]) else if (l[0] > p3[p3.getSize() - 1])
{ {
printf("无牌可出,跳过\n"); printf("无牌可出,跳过\n");
pass_num++; pass_num++;
} }
else else
@ -229,9 +229,9 @@ Begin:
if (l[0] < p3[i]) if (l[0] < p3[i])
{ {
std::cout << "打出" << PU[l.firstInsert((p3).remove(i))]; std::cout << "打出" << PU[l.firstInsert((p3).remove(i))];
printf(",剩余%d张牌\n", p3.getSize()); printf(",剩余%d张牌\n", p3.getSize());
pass_num = 0; pass_num = 0;
break; break;
} }
@ -239,20 +239,20 @@ Begin:
if (p3.getSize() == 0) if (p3.getSize() == 0)
{ {
s.finish(2); s.finish(2);
printf("玩家C出完所有牌\n"); printf("玩家C出完所有牌\n");
finish_num++; finish_num++;
pass_num = 0; pass_num = 0;
} }
} }
else else
printf("玩家C轮空\n"); printf("玩家C轮空\n");
round++; round++;
} }
printf("=====================================\n"); printf("=====================================\n");
printf("分数结算:\n"); printf("分数结算:\n");
printf("玩家A:%d分\n", s.score(0)); printf("玩家A:%d分\n", s.score(0));
printf("玩家B:%d分\n", s.score(1)); printf("玩家B:%d分\n", s.score(1));
printf("玩家C:%d分\n", s.score(2)); printf("玩家C:%d分\n", s.score(2));
system("pause"); system("pause");