首页 > 其他分享 >CF1741A Compare T-Shirt Sizes

CF1741A Compare T-Shirt Sizes

时间:2022-10-14 16:22:46浏览次数:83  
标签:Compare ch Shirt puts int text -- CF1741A

题链:cf lugou

赛时吃了一波罚时(? 代码挺长(?

Description

给你两个衣服尺码,比较他们的大小。

Analysis

细节题。

首先我们将所有尺码分为 \(\text{S}\)、\(\text{M}\)、\(\text{L}\) 三类,其中仅 \(\text{M}\) 码前不会有 \(\text{X}\)。

下面分为两类:

  1. 异类:直接比较末字符所指向的类别,直接输出比较结果。

  2. 同类:向前查询 \(\text{X}\) 的个数,再根据 \(\text{S}\) 和 \(\text{L}\) 的加 \(\text{X}\) 比大小规则输出结果。

Code

仅供参考。

#include <iostream>
#include <stdio.h>
using namespace std;
string a, b;
int ch[250];
int main(void) {
	ch['S'] = 0, ch['M'] = 1, ch['L'] = 2;
	int t; for (cin >> t; t--; ) {
		cin >> a >> b; int n = a.length(), m = b.length(); --n, --m;
		if (a[n] == 'M') {
			if (b[m] == 'M') puts("=");
			if (b[m] == 'S') puts(">");
			if (b[m] == 'L') puts("<");
			continue;
		}
		if (a[n] == 'L' && b[m] != 'L') {
			puts(">"); continue;
		}
		if (a[n] == 'S' && b[m] != 'S') {
			puts("<"); continue;
		}
		//以上为异类
		//以下为同类
		if (a[n] == 'S') {
			if (n > m) puts("<");
			if (n == m) puts("=");
			if (n < m) puts(">");
			continue;
		}
		if (a[n] == 'L') {
			if (n > m) puts(">");
			if (n == m) puts("=");
			if (n < m) puts("<");
		}
	}
	return 0;
}

The end. Thanks.

(路过一顶

标签:Compare,ch,Shirt,puts,int,text,--,CF1741A
From: https://www.cnblogs.com/dry-ice/p/cf1741a.html

相关文章