跳到正文

题解

[ABC277B] Playing Cards Validation 题解

冷却心约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月23日
篇幅
约 2 分钟

版本

  1. v1当前

题意

给定 nn 个长度为 22 的字符串,判断是否合法:

  • 字符串第 11 个字符只能为 H,D,C,S\mathtt{H,D,C,S}。

  • 字符串第 22 个字符只能为 A,2,3,4,5,6,7,8,9,T,J,Q,K\mathtt{A,2,3,4,5,6,7,8,9,T,J,Q,K}。

  • 任意两个字符串不能相同。

解法

按题意模拟判断即可。输入时先判断第 11 个字符是否符合要求,再判断第 22 个字符,输入完毕后再 双重循环判断一下有没有重复的。(如果数据再强一些可以用 set 优化)

Code

C++
#include<bits/stdc++.h>
#define LL long long
#define Fcin\
	ios :: sync_with_stdio(0);\
	cin.tie(0); cout.tie(0)
using namespace std;
const LL N = 1e2 + 10;
LL n, k;
string s[N];
int main(){
    Fcin;
    cin >> n;
	for (LL i = 1; i <= n; i ++){
		cin >> s[i];
		char c = s[i][0];
		if (c != 'H' && c != 'D' && c != 'C' && c != 'S'){
			cout << "No";
			return 0;
		}
		c = s[i][1];
		if (c != 'A' && (isdigit(c) && c - '0' <= 1) && c != 'T' && c != 'J' && c != 'Q' && c != 'K'){
			cout << "No";
			return 0;
		}
	}

	for (LL i = 1; i <= n; i ++)
		for (LL j = i + 1; j <= n; j ++)
			if (s[i] == s[j]){
				cout << "No";
				return 0;
			}
	cout << "Yes";
	return 0;
}
原文