题解 | 打牌

打牌

https://www.nowcoder.com/practice/82442ee76977479e8ab4b88dfadfca9f

#include <iostream>
#include<string>
using namespace std;

int main() {
    string str1, str2;
    while (cin >> str1 >> str2) {
        
        if (str2.size() < 5) {
            bool big = false;
            for (int i = 0, j = 0; i < str1.size() - 1;i++) {
                if (str1[i] > str2[0]) {
                    j = i;
                    while (str1[j] == str1[i])j++;
                    if (j - i >= str2.size()) {
                        big = true;
                    }
                    //if (j == str1.size() - 1)break;
                    i = j-1;
                }
            }
            if(big) puts("YES");
            else puts("NO");
        }
        else {
            bool visit[10] = { 0 };
            int res = 0;
            int count = 0;
            int last = -1;
            for (int j = str1.size() - 1; j >= 0; j--) {
                if (!visit[str1[j]-'0'] && str1[j] > str2[0]) {
                    if (last != str1[j] - '0'+1)count = 0;
                    last = str1[j] - '0';
                    count++;
                    res = max(res, count);
                    visit[str1[j] - '0'] = true;
                }
            }
            if (res >= str2.size()) {
                puts("YES");
            }
            else puts("NO");
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

cpp苦手:一眼ddl
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务