• 51nod 1127 最短的包含字符串


    给出一个字符串,求该字符串的一个子串s,s包含A-Z中的全部字母,并且s是所有符合条件的子串中最短的,输出s的长度。如果给出的字符串中并不包括A-Z中的全部字母,则输出No Solution。
     
    Input
    第1行,1个字符串。字符串的长度 <= 100000。
    Output
    输出包含A-Z的最短子串s的长度。如果没有符合条件的子串,则输出No Solution。
    Input示例
    BVCABCDEFFGHIJKLMMNOPQRSTUVWXZYZZ
    Output示例
    28

    尺取。
    代码:
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #define MAX 100001
    using namespace std;
    
    char s[MAX];
    int m = MAX;
    int main() {
        int head = 0,tail = 0,c = 0,num[26] = {0};
        scanf("%s",s);
        while(s[tail] || c == 26) {
            if(c < 26) {
                int d = s[tail ++] - 'A';
                if(!num[d]) c ++;
                num[d] ++;
            }
            else {
                m = min(m,tail - head);
                int d = s[head ++] - 'A';
                if(num[d] == 1) c --;
                num[d] --;
            }
        }
        if(m != MAX)printf("%d
    ",m);
        else printf("No Solution
    ");
    }
  • 相关阅读:
    ajax的一些知识
    前端性能优化汇总
    jquery实现一些小动画二
    python简单日志处理
    逆波兰式---C实现
    java常见异常
    Hive与HBase集成及常见问题解决
    SQL for HBase
    Demystifying the Skip Scan in Phoenix
    Difference between DDL, DML and DCL commands
  • 原文地址:https://www.cnblogs.com/8023spz/p/9840305.html
Copyright © 2020-2023  润新知