51Nod - 1127 最短的包含字符串
给出一个字符串,求该字符串的一个子串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 最短的包含字符串的更多相关文章
- 51Nod 1127 最短的包含字符串 (尺取法)
#include <iostream> #include <algorithm> #include <string> #include <cstring> ...
- 51 nod 1127最短的包含字符串(尺取法)
1127 最短的包含字符串 收藏 关注 给出一个字符串,求该字符串的一个子串S,S包含A-Z中的全部字母,并且S是所有符合条件的子串中最短的,输出S的长度.如果给出的字符串中并不包括A-Z中的全 ...
- [51NOD1127]最短的包含字符串(尺取法)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1127 思路:尺取法,一开始我考虑更新右指针,直到遇到一个和l指 ...
- 51nod1127 最短的包含字符串 尺取法
Bryce1010模板 #include <bits/stdc++.h> using namespace std; typedef long long LL; map<char,LL ...
- sql server 查找包含字符串的对象
sql server 查找包含字符串的对象 SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, o.type, o.type_ ...
- css3选择器的比较(二) -- 包含字符串
二. 包含“字符串” 两种用法的区别是: a. “~=”,需要用空格分割, b. "*=",不需要任何分隔符 1. 资料 a) b) 2. html代码 <div tit ...
- strstr() strpos() 获取db报错,判断报错中是否包含字符串,判断错误类型
model中直接获取添加公司的错误.(公司名称不能重复) $enterprise_id = $this->add($enterprisedata ); $err = $this->getD ...
- js判断字符串str是否包含字符串substr
js判断字符串str是否包含字符串substr: function addUser(id,realName){ var userids = $("#userids").val(); ...
- idea 快捷键以及包含字符串文件搜索
1.idea也有一个类似于eclipse的包含字符串文件搜索(特别实用) idea 里按快捷键:ctrl+H 2.下图是idea的快捷键汇总 3.debug调试 F5:跳入方法 F6:向下逐行调试 ...
随机推荐
- PAT 甲级 1059 Prime Factors
https://pintia.cn/problem-sets/994805342720868352/problems/994805415005503488 Given any positive int ...
- Hibernate学习--hibernate延迟加载原理-动态代理(阿里电面)
在正式说hibernate延迟加载时,先说说一个比较奇怪的现象吧:hibernate中,在many-to-one时,如果我们设置了延迟加载,会发现我们在eclipse的调试框中查看one对应对象时,它 ...
- Dbgrid控件多重选择的怪问题。BookMarkList,BookMark,使用书签,用的ADOQuery控件。100分送上,急阿!!!请高手帮忙!
Dbgrid控件多重选择的怪问题.BookMarkList,BookMark,使用书签,用的ADOQuery控件.100分送上,急阿!!!请高手帮忙! ( 积分: 100 )<br />p ...
- 第134天:移动web开发的一些总结(二)
1.响应式布局 开发一个页面,在所有的设备上都能够完美展示. 媒体查询:@media screen and (max-width:100px) { } 媒体类型:screen(屏幕) print(打印 ...
- 对xml的操作使用的类XElement的使用
操作xml的类比较多,发现XElement类操作xml极其方便,下面列举一些操作方法 1.创建xml XElement xml = new XElement("root", new ...
- 51nod 1677 treecnt(思维)
题意: 给定一棵n个节点的树,从1到n标号.选择k个点,你需要选择一些边使得这k个点通过选择的边联通,目标是使得选择的边数最少. 现需要计算对于所有选择k个点的情况最小选择边数的总和为多少. 考虑每条 ...
- Java虚拟机的内存管理----垃圾收集器
1.Serial收集器 优点,是简单而高效,单线程避免了线程交互的开销. 缺点,进行垃圾回收时需要Stop the world(暂停所有用户线程). 2.ParNew收集器 它是Serial收集器的多 ...
- 自动化生成html报告
package Utils; import java.io.File; import java.util.Date; import org.apache.commons.lang3.time.Date ...
- Unified Networking Lab 安装使用IOL镜像
Unified Networking Lab 安装使用IOL镜像 Unified Networking Lab 很久以前,在一个星系远的地方,很远的工程师们为eBay寻找二手路由器来满足家庭实验的需求 ...
- 修改gcc/g++默认include路径
修改gcc/g++默认include路径 转自:http://www.network-theory.co.uk/docs/gccintro/gccintro_23.htmlhttp://ilewen. ...