题解 | #打牌#
打牌
http://www.nowcoder.com/practice/82442ee76977479e8ab4b88dfadfca9f
简单粗暴解法c++
#include<iostream>
#include<map>
#include<set>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string a, b;
map<int, string> mp;
mp[0] = "12345";
mp[1] = "23456";
mp[2] = "34567";
mp[3] = "45678";
mp[4] = "56789";
while (cin >> a >> b) {
int len = b.size();
bool flag = false;
switch (len) {
case 1:
for (int i = 0; i < a.size(); ++i)
if (a[i] > b[0]) {
flag = true;
break;
}
break;
case 2:
for (int i = 0; i < a.size() - 1; ++i) {
if (a[i] == a[i + 1] && (a[i] - '0') * 10 + (a[i + 1] - '0') > (b[0] - '0') * 10 + (b[1] - '0')) {
flag = true;
break;
}
}
break;
case 3:
for (int i = 0; i < a.size() - 2; ++i)
if (a[i] == a[i + 1] && a[i + 1]== a[i + 2] && (a[i] - '0') * 100 + (a[i + 1] - '0') * 10 + a[i + 2] - '0' > (b[0] - '0') * 100 + (b[1] - '0') * 10 + b[2] - '0') {
flag = true;
break;
}
break;
case 4:
for (int i = 0; i < a.size() - 3; ++i)
if (a[i] == a[i + 1] && a[i + 1] == a[i + 2] && a[i + 2] == a[i + 3] && (a[i] - '0') * 1000 + (a[i + 1] - '0') * 100 + (a[i + 2] - '0') * 10 + a[i + 3] - '0' > (b[0] - '0') * 1000 + (b[1] - '0') * 100 + (b[2] - '0') * 10 + b[3] - '0') {
flag = true;
break;
}
break;
default:
int i = 0;
set<char> Set;
for(int i = 0;i < a.size();++i)
Set.insert(a[i]);
string tmp = "";
for(auto it : Set)
tmp = tmp + it;
a = tmp;
for (; i < mp.size(); ++i)
if (mp[i] == b)
break;
for (int j = i + 1; j <= 4; ++j) {
if (a.find(mp[j]) != string::npos) {
flag = true;
break;
}
}
break;
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}