随机抽出5张牌,判断抽出的5张牌是不是连续的扑克牌,不许使用排序算法。
using System;
using System.Collections.Generic;
namespace calpoker
{
class Program
{
static bool compareStringArray(string[] srcArr, string[] destArr) {
bool isEquals = true;
int len = srcArr.Length;
for(int i=0;i<srcArr.Length;i++){
if(srcArr[i]!=destArr[i]){
isEquals = false;
break;
}
}
return isEquals;
}
static void Main(string[] args)
{
if(args.Length<5){
Console.WriteLine("参数个数不足!");
Environment.Exit(-1);
}
string[] arrOrder = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
List<string[]> compareArrs = new List<string[]>();
for(int i=0;i<arrOrder.Length-4;i++) {
string[] strArr = new string[5];
strArr[0] = arrOrder[i];
strArr[1] = arrOrder[i+1];
strArr[2] = arrOrder[i+2];
strArr[3] = arrOrder[i+3];
strArr[4] = arrOrder[i+4];
compareArrs.Add(strArr);
}
bool isSequnced = false;
foreach(string[] arr in compareArrs) {
if(compareStringArray(arr,args)){
isSequnced = true;
break;
}
}
string isSequncedStr = isSequnced?"是":"不是";
Console.Write("输入的数组:");
Console.Write("[");
for(int i=0;i<args.Length;i++){
if(i<4){
Console.Write(args[i]+" ");
}else{
Console.Write(args[i]);
}
}
Console.Write("]");
Console.WriteLine($"{isSequncedStr}连续的扑克牌序列");
}
}
}
程序输出如下: