给出一个字符串,求该字符串的一个子串s,s包含A-Z中的全部字母,并且s是所有符合条件的子串中最短的,输出s的长度。如果给出的字符串中并不包括A-Z中的全部字母,则输出No Solution。

Input

第1行,1个字符串。字符串的长度 <= 100000。

Outpu

t输出包含A-Z的最短子串s的长度。如果没有符合条件的子串,则输出No Solution。

Sample Input

BVCABCDEFFGHIJKLMMNOPQRSTUVWXZYZZ

Sample Output

28

尺取法,判断标准是是否含有全部26个字母。
 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<iostream>
using namespace std;
char con[];
int main()
{
int i,p,j,k;
int head,tail,ans,flag,big;
int check[]={};
gets(con);
k=strlen(con);
big=;
head=tail=;
flag=;
ans=;
check[con[]-]++;
while()
{
if(tail>head||head>=k||tail>=k||head<||tail<)
break;
if(flag<)
{
head++;
ans++;
if(check[con[head]-]==)
{
flag++;
}
check[con[head]-]++;
}
else
{
if(ans<big)
big=ans;
ans--;
check[con[tail]-]--;
if(check[con[tail]-]==)
flag--;
tail++;
}
}
if(big==)
printf("No Solution\n");
else
printf("%d\n",big);
return ;
}

51Nod - 1127 最短的包含字符串的更多相关文章

  1. 51Nod 1127 最短的包含字符串 (尺取法)

    #include <iostream> #include <algorithm> #include <string> #include <cstring> ...

  2. 51 nod 1127最短的包含字符串(尺取法)

    1127 最短的包含字符串   收藏  关注 给出一个字符串,求该字符串的一个子串S,S包含A-Z中的全部字母,并且S是所有符合条件的子串中最短的,输出S的长度.如果给出的字符串中并不包括A-Z中的全 ...

  3. [51NOD1127]最短的包含字符串(尺取法)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1127 思路:尺取法,一开始我考虑更新右指针,直到遇到一个和l指 ...

  4. 51nod1127 最短的包含字符串 尺取法

    Bryce1010模板 #include <bits/stdc++.h> using namespace std; typedef long long LL; map<char,LL ...

  5. sql server 查找包含字符串的对象

    sql server 查找包含字符串的对象 SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, o.type, o.type_ ...

  6. css3选择器的比较(二) -- 包含字符串

    二.  包含“字符串” 两种用法的区别是: a. “~=”,需要用空格分割, b. "*=",不需要任何分隔符 1. 资料 a) b)  2. html代码 <div tit ...

  7. strstr() strpos() 获取db报错,判断报错中是否包含字符串,判断错误类型

    model中直接获取添加公司的错误.(公司名称不能重复) $enterprise_id = $this->add($enterprisedata ); $err = $this->getD ...

  8. js判断字符串str是否包含字符串substr

    js判断字符串str是否包含字符串substr: function addUser(id,realName){ var userids = $("#userids").val(); ...

  9. idea 快捷键以及包含字符串文件搜索

    1.idea也有一个类似于eclipse的包含字符串文件搜索(特别实用) idea 里按快捷键:ctrl+H 2.下图是idea的快捷键汇总 3.debug调试 F5:跳入方法   F6:向下逐行调试 ...

随机推荐

  1. Hadoop环境搭建(三)

    长久没用了,再次登陆Ubuntu的时候提醒密码错误,然后就进入了guest session,依然可以进入系统进行工作但身份是guest,于是开始了找回密码的漫漫长路. 首先,在guest模式下,右上角 ...

  2. 【第一周】c++实现词频统计

    coding.net地址:https://coding.net/u/Boxer_ ssh:git@git.coding.net:Boxer_/homework.git ---------------- ...

  3. linux下c/c++的文件操作

    opendir,readdir,closedir, stat()查询文件状态 open(), O_TRUNC这个Flag会把打开的文件清零... 文件锁:fcntl, F_GETLK , F_SETL ...

  4. PHP创建对象的几种形式

    创建对象的几种形式 class  C1{ var  $p1 = 1; //定义一个属性: } 形式1: $o1 = new C1(); //通过一个类,去new出一个对象 形式2: $o2 = new ...

  5. 【Python】Python的time和datetime模块

    time 常用的有time.time()和time.sleep()函数. import time print(time.time()) 1499305554.3239055 上面的浮点数称为UNIX纪 ...

  6. Arrays.toString 如果传入的是对象 那么调用的是此对象的toString

    Arrays.toString(Object[] obj) 如果传入参数的是对象 那么调用的是此对象的toString

  7. GLSL反转矩阵inverse

    低版本 vertex shader 可以使用,通常用来反转TBN矩阵,但是计算量很大. 代码来自 OpenGL Mathematics (GLM) mat4 inverse_mat4(mat4 m) ...

  8. [BZOJ4540][HNOI2016]序列 莫队

    4540: [Hnoi2016]序列 Time Limit: 20 Sec  Memory Limit: 512 MB Description 给定长度为n的序列:a1,a2,…,an,记为a[1:n ...

  9. Intel WIDI (Wireless Display) 相关技术知识分析

    一. WIFI 1.如何查找WIFI设备 非p2p设备 Beacons 包(同步,SSID) 速率 1M/s 2.4G HZ 13个信道,1,6,11三个信道不重叠 2.P2P 认证 客户端在每个通道 ...

  10. [洛谷P5190][COCI 2010] PROGRAM

    题目大意:给你$k(k\leqslant10^6)$个数,$f(x)$表示$x$的约数在$k$个数中出现的次数,在这任何数都是$0$的约数.$m(m\leqslant10^6)$次询问,每次给出$l, ...