规则是:
比大小,从小到大依次是2,3,4,5,6,7,8,9,10,J,Q,K,A
给两边一样的牌
然后都翻出上面第一张牌,大的能把自己跟对面的牌收到最下面;
如果一样大,就进行War:把后三张都拿出来,比第四张(War的话,只算一次battle)
赢得能把全部收回去
先没牌的输(当时我还以为是谁赢得多谁赢)
然后 output :获胜者(1或2)+ “ ” + 一共比了多少次
虽然写的挺垃圾的,但还是过了
思路就当打牌一样
4个队列
两个手牌队列
两个出牌队列
计分板
Battle{
①出手牌队列
②入出牌队列
③比大小(判断字符串第一个char,返回相应的int,J=11,Q=12,K=13,A=14)(10就直接判断1,反正也没有1牌,只有A)
④赢的收回入手牌队列
递归Battle
}
退出条件是有一方的Queue.Count ==0 或者 在War的时候Queue.Count ==0(则判定为平局“PAT”)
这里遇到最坑的是放回手牌的顺序,卡了我好久,,,
还有个坑是获胜条件是把对手的手牌全收了(一开始以为是谁赢得多谁赢),所以按道理只需要一个统计次数的就行了,不用统计谁赢的多;(asw[]不需要)
这里是固定P1的在P2的前面,所以按道理其实只需要一个出牌队列就行了,但是懒得改了。
反正代码里面好多脱裤子放屁的,但是结果是过了的
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
class Solution
{
static void Main(string[] args)
{
Queue<string> cardp1 = new Queue<string>();
Queue<string> cardp2 = new Queue<string>();
Queue<string> temp1 = new Queue<string>();
Queue<string> temp2 = new Queue<string>();
int n = int.Parse(Console.ReadLine()); // the number of cards for player 1
for (int i = 0; i < n; i++)
{
cardp1.Enqueue(Console.ReadLine()); // the n cards of player 1
}
int m = int.Parse(Console.ReadLine()); // the number of cards for player 2
for (int i = 0; i < m; i++)
{
cardp2.Enqueue(Console.ReadLine()); // the m cards of player 2
}
// Write an answer using Console.WriteLine()
// To debug: Console.Error.WriteLine("Debug messages...");
Battle(cardp1,cardp2,temp1,temp2);
int count = asw[0] +asw[1];
if(wins[0]> wins[1]){
Console.WriteLine("1"+" "+count);
}else if(wins[0]< wins[1]){
Console.WriteLine("2"+" "+ count);
}
else{
Console.WriteLine("PAT");
}
}
static int[] asw = new int[2]{0,0};
static int[] wins = new int[2]{0,0};
static int[] Battle(Queue<string> cardp1,Queue<string> cardp2,Queue<string> temp1, Queue<string> temp2){
if(cardp1.Count == 0){
wins[1] =1;
return wins;
}
if(cardp2.Count == 0){
wins[0] = 1;
return wins;
}
string p1 = cardp1.Dequeue();
string p2 = cardp2.Dequeue();
temp1.Enqueue(p1);
temp2.Enqueue(p2);
int score = CheckL(p1,p2);
if(score == 1){
Win(cardp1,temp1);
Win(cardp1,temp2);
asw[0]++;
Battle(cardp1,cardp2,temp1,temp2);
}else if(score == -1){
Win(cardp2,temp1);
Win(cardp2,temp2);
asw[1]++;
Battle(cardp1,cardp2,temp1,temp2);
}else if(score == 0){
if(!Btl(temp1,cardp1)) return wins;
if(!Btl(temp1,cardp1)) return wins;
if(!Btl(temp1,cardp1)) return wins;
if(!Btl(temp2,cardp2)) return wins;
if(!Btl(temp2,cardp2)) return wins;
if(!Btl(temp2,cardp2)) return wins;
Battle(cardp1,cardp2,temp1,temp2);
}
return asw;
}
static bool Btl(Queue<string> temp, Queue<string> card){
if(card.Count != 0) {
temp.Enqueue(card.Dequeue());
return true;
}
return false;
}
static int CheckL(string p1, string p2){
if(Check(p1)>Check(p2)){
return 1;
}else if(Check(p1)<Check(p2)){
return -1;
}
return 0;
}
static int Check(string temp){
switch (temp[0]){
case 'J':
return 11;
case 'Q':
return 12;
case 'K':
return 13;
case 'A':
return 14;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case '1':
return 10;
}
return 0;
}
static void Win(Queue<string> winer, Queue<string> temp){
while(temp.Count >0){
winer.Enqueue(temp.Dequeue());
}
}
}