什么是自动 t1=std::make_tuple(case1==case2,整数)的值

what is value of auto t1=std::make_tuple(case1==case2,integer)

本文关键字:case2 case1 的值 整数 tuple make t1 什么 std      更新时间:2023-10-16

**描述

first, each player draws a single card from the deck
if one of the players drew a card of the winning suit and the other did not, then the player who drew a card of the winning suit wins the round
otherwise, the numbers written on the cards decide: if one player drew a card with a greater number on it than the other player, the player with the greater number wins, otherwise, if both players drew cards with the same numbers, the round ends in a draw
after the round is ended, the players return the cards they drew into the deck

** *在第一行中,有一个字符

表示胜诉的诉讼。

在第二行中,有一个整数

表示要玩的回合数。

接下来的每一个 线表示在单轮游戏中抽出的牌,包含四个空格分隔的值:,分别表示玩家 1 张牌的花色、玩家 1 张牌上的花色、玩家 2 张牌的花色和玩家的 2 张牌的数量。*

input:-
B
5
A 2 B 1
A 7 D 2
B 5 D 13
B 3 B 1
A 12 C 12
int main() {
char winning_suit;
std::cin >> winning_suit;
unsigned tests;
std::cin >> tests;
while (tests--) {
char suit1, suit2;
int number1, number2;
std::cin >> suit1 >> number1 >> suit2 >> number2;
auto t1 = std::make_tuple(suit1 == winning_suit, number1);
auto t2 = std::make_tuple(suit2 == winning_suit, number2);
if (t1 > t2) {
std::cout << "Player 1 winsn";
} else if (t1 < t2) {
std::cout << "Player 2 winsn";
} else {
std::cout << "Drawn";
}
}
}
output:-
Player 2 wins
Player 1 wins
Player 1 wins
Player 1 wins
Draw

语句

auto t1 = std::make_tuple(suit1 == winning_suit, number1);
auto t2 = std::make_tuple(suit2 == winning_suit, number2);

声明和初始化std::tuple<bool, int>

第一次循环时,它们具有以下值

{ false, 2 }
{ true, 1 }

然后使用std::tuple::operator>std::tuple::operator<进行比较,根据第一个元素对它们进行排序,然后按第二个元素对它们进行排序。这是一个词典顺序,特别是

偏序集合的笛卡尔积上的订单

这里意味着获胜花色中的所有牌都大于其他花色中的所有牌,当花色平局时,编号较高的牌大于编号较低的牌。