Compare T-Shirt Sizes
题目连结
解题
要先了解以下状况
L
永远大于M
或S
(不管加了几个X)M
永远大于S
(不管加了几个X)尾号
相同L
:X
越多==>越大S
:X
越多==>越小M
没有在加X的(ex:XM
is wrong size)
这样就能决定如何比较大小
看两个是否相同大小比尾号(尾号不同就略3.
)比X
```cpp#include <iostream>#include <vector> //一开始以为会用到#include <string> //原本要用findusing namespace std;int main(int argc, char const *argv[]){ int t; cin >> t; while (t--) { string t1, t2; // input 1 2 string n1, n2; // 字尾号码 (没试过不知道char行不行) /* 核心思路:(暴力解) 0.一样直接输出"=" 1.先比尾号(尾号大小确定再多X也没用) 2.尾号相同看是S还是L 3.X越多在S中越小在L中越大,反之 p.s. 题目不存在XM、LL等非正常衣服尺寸。故不用另外排除 */ cin >> t1 >> t2; n1 = t1[t1.length() - 1]; // 抓取字尾(S、M、L) n2 = t2[t2.length() - 1]; // 抓取字尾(S、M、L) if (t1 == t2) // same { cout << "=" << endl; } else if (n1 == "L" && n2 != "L") // L >( M or S ) { cout << ">" << endl; } else if (n1 != "L" && n2 == "L") { cout << "<" << endl; } else if (n1 == "M" && n2 == "S") // also S > M { cout << ">" << endl; } else if (n2 == "M" && n1 == "S") { cout << "<" << endl; } else if (n1 == "S" && n2 == "S") // 在S号中 X越多代表越小 { if (t1.length() > t2.length()) { cout << "<" << endl; } else { cout << ">" << endl; } } else if (n1 == "L" && n2 == "L") // 在L号中,X越多代表越大 { if (t1.length() > t2.length()) { cout << ">" << endl; } else { cout << "<" << endl; } } } return 0;}