给出一个字符串,求该字符串的一个子串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

  1. 28
  2.  
  3. 尺取法,判断标准是是否含有全部26个字母。
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<math.h>
  5. #include<algorithm>
  6. #include<queue>
  7. #include<stack>
  8. #include<deque>
  9. #include<iostream>
  10. using namespace std;
  11. char con[];
  12. int main()
  13. {
  14. int i,p,j,k;
  15. int head,tail,ans,flag,big;
  16. int check[]={};
  17. gets(con);
  18. k=strlen(con);
  19. big=;
  20. head=tail=;
  21. flag=;
  22. ans=;
  23. check[con[]-]++;
  24. while()
  25. {
  26. if(tail>head||head>=k||tail>=k||head<||tail<)
  27. break;
  28. if(flag<)
  29. {
  30. head++;
  31. ans++;
  32. if(check[con[head]-]==)
  33. {
  34. flag++;
  35. }
  36. check[con[head]-]++;
  37. }
  38. else
  39. {
  40. if(ans<big)
  41. big=ans;
  42. ans--;
  43. check[con[tail]-]--;
  44. if(check[con[tail]-]==)
  45. flag--;
  46. tail++;
  47. }
  48. }
  49. if(big==)
  50. printf("No Solution\n");
  51. else
  52. printf("%d\n",big);
  53. return ;
  54. }

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. PAT 甲级 1059 Prime Factors

    https://pintia.cn/problem-sets/994805342720868352/problems/994805415005503488 Given any positive int ...

  2. Hibernate学习--hibernate延迟加载原理-动态代理(阿里电面)

    在正式说hibernate延迟加载时,先说说一个比较奇怪的现象吧:hibernate中,在many-to-one时,如果我们设置了延迟加载,会发现我们在eclipse的调试框中查看one对应对象时,它 ...

  3. Dbgrid控件多重选择的怪问题。BookMarkList,BookMark,使用书签,用的ADOQuery控件。100分送上,急阿!!!请高手帮忙!

    Dbgrid控件多重选择的怪问题.BookMarkList,BookMark,使用书签,用的ADOQuery控件.100分送上,急阿!!!请高手帮忙! ( 积分: 100 )<br />p ...

  4. 第134天:移动web开发的一些总结(二)

    1.响应式布局 开发一个页面,在所有的设备上都能够完美展示. 媒体查询:@media screen and (max-width:100px) { } 媒体类型:screen(屏幕) print(打印 ...

  5. 对xml的操作使用的类XElement的使用

    操作xml的类比较多,发现XElement类操作xml极其方便,下面列举一些操作方法 1.创建xml XElement xml = new XElement("root", new ...

  6. 51nod 1677 treecnt(思维)

    题意: 给定一棵n个节点的树,从1到n标号.选择k个点,你需要选择一些边使得这k个点通过选择的边联通,目标是使得选择的边数最少. 现需要计算对于所有选择k个点的情况最小选择边数的总和为多少. 考虑每条 ...

  7. Java虚拟机的内存管理----垃圾收集器

    1.Serial收集器 优点,是简单而高效,单线程避免了线程交互的开销. 缺点,进行垃圾回收时需要Stop the world(暂停所有用户线程). 2.ParNew收集器 它是Serial收集器的多 ...

  8. 自动化生成html报告

    package Utils; import java.io.File; import java.util.Date; import org.apache.commons.lang3.time.Date ...

  9. Unified Networking Lab 安装使用IOL镜像

    Unified Networking Lab 安装使用IOL镜像 Unified Networking Lab 很久以前,在一个星系远的地方,很远的工程师们为eBay寻找二手路由器来满足家庭实验的需求 ...

  10. 修改gcc/g++默认include路径

    修改gcc/g++默认include路径 转自:http://www.network-theory.co.uk/docs/gccintro/gccintro_23.htmlhttp://ilewen. ...