更新 1.cpp

Signed-off-by: ChenKaiLiuG <ckliu119@gmail.com>
This commit is contained in:
2025-12-30 06:43:50 +00:00
parent 12209cd342
commit ed5cb1df40

22
1.cpp
View File

@@ -8,34 +8,33 @@
#include <windows.h>
using namespace std;
// test input
int try_num(string b)
{
int bb;
try
{
bb = stoi(b);
bb = stoi(b); //try int
}
catch (invalid_argument)
catch (invalid_argument) // catch invaild input
{
return -1;
}
return bb;
}
string cardname[21];
int score[7];
string cardname[21];
int score[7];
//define cardname
array<int, 21> calculate(int arr[40])
{
array<int, 21> cal;
fill(cal.begin(), cal.end(), 0);
fill(cal.begin(), cal.end(), 0); // initilize
for (int j = 0; j < 40; j++)
{
if (arr[j] == -1)
continue;
else
cal[arr[j]]++;
if (arr[j] == -1) continue; // pass blank
else cal[arr[j]]++;
}
return cal;
}
@@ -57,6 +56,7 @@ void display_p(int arr[][40], int num)
cout << "\n";
}
}
//display players' cards
void display_s(int arr2[][3], int flag[5], int num)
{
@@ -65,6 +65,7 @@ void display_s(int arr2[][3], int flag[5], int num)
cout << "Stack " << i + 1 << ": ";
for (int j = 0; j < 3; j++)
{
// show color by ANSI code
if (arr2[i][j] == 1)
cout << " \033[31m red \033[0m";
else if (arr2[i][j] == 2)
@@ -85,10 +86,11 @@ void display_s(int arr2[][3], int flag[5], int num)
cout << " +2_point ";
}
if (flag[i] == 2)
cout << "(taken)";
cout << "(taken)"; // mark taken cards
cout << "\n";
}
}
//dispaly stack
void getcard(int deck[76], bool vis[76], int stack[5][3], int flag_s[5], int pynum, int& counter, int cp_chk)
{