make_pair用法

#include<bits/stdc++.h>
using namespace std;
#define mp make_pair

class DeckOfCards{
string IsValid(int n,vector<int>value,string suit)
{
    set<pair<int,char>>deck;
    for(int i=0;i<value.size();i++){
        deck.insert(mp(value[i],suit[i]));
    }
    if(deck.size()<n){
        return "Not perfect";
    }
    for(int i=0;i<value.size();i++){
        for(int j=0;j<value.size();j++)
    {
        
        if(deck.find(mp(value[i],suit[j]))==deck.end()){如果set里没这个pair,not perfect
            return "Not perfect";
        }
    }
    }
    return "Perfect";
}
};


Problem Statement

 

You found a deck of slightly non-traditional playing cards. Each card has a value and a suit. The value of each card is a positive integer, and the suit is a lowercase English letter ('a'-'z'). We will use (v, s) to denote a card with value v and suit s.


You want to know whether the deck is perfect. A perfect deck has two properties:

  • All cards in the deck are distinct. (I.e., no two cards share both value and suit.)
  • For any two cards (v1, s1) and (v2, s2) in the deck, the deck also contains the cards (v1, s2) and (v2, s1).

You are given the following data:

  • an int n: the number of cards in the deck
  • a vector <int> value with n elements: the values of the cards in the deck
  • a string suit with n elements: the suits of the cards in the deck
More precisely, for each valid i, (value[i], suit[i]) is one of the cards in the deck. Return "Perfect" if the deck is perfect and "Not perfect" otherwise. Note that the quotes are only for clarity and that the return value is case-sensitive.

Definition

 
Class:DeckOfCards
Method:IsValid
Parameters:int, vector <int>, string
Returns:string
Method signature:string IsValid(int n, vector <int> value, string suit)
(be sure your method is public)

Limits

 
Time limit (s):2.000
Memory limit (MB):256

Constraints

-n will be between 1 and 50, inclusive.
-value will contain exactly n elements.
-Each element of value will be between 1 and 1,000,000,000, inclusive.
-suit will be of length n exactly.
-Suit will only contain lower-case alphabets ('a'-'z').

Examples

0) 
 
1
{10}
"z"
Returns: "Perfect"
There is only one card in the deck: (10, 'z'). The deck is obviously perfect.
1) 
 
3
{1,2,3}
"hhh"
Returns: "Perfect"
2) 
 
4
{2,3,2,3}
"hcch"
Returns: "Perfect"
3) 
 
3
{1,1,1}
"hch"
Returns: "Not perfect"
This deck is not perfect because it contains two copies of the card (1, 'h').
4) 
 
4
{1,2,3,4}
"hhcc"
Returns: "Not perfect"
This deck is not perfect. For example, the presence of cards (1, 'h') and (3, 'c') implies that the cards (3, 'h') and (1, 'c') should also be in the deck, but both of them are missing.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值