1127 最短的包含字符串
来源:互联网 发布:贝卡谷地空战真实数据 编辑:程序博客网 时间:2024/05/06 09:23
给出一个字符串,求该字符串的一个子串S,S包含A-Z中的全部字母,并且S是所有符合条件的子串中最短的,输出S的长度。如果给出的字符串中并不包括A-Z中的全部字母,则输出No Solution。
Input
第1行,1个字符串。字符串的长度 <= 100000。
Output
输出包含A-Z的最短子串长度。如果没有符合条件的子串,则输出No Solution。
Input示例
BVCABCDEFFGHIJKLMMNOPQRSTUVWXZYZZ
Output示例
28
#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <string>#include <functional>#include <cmath>#include <set>#include <queue>#include <algorithm>#include <vector>#include <map>#include <stack>using namespace std;#define esp 1e-8const double PI = acos(-1.0);const double e = 2.718281828459;const int inf = 2147483647;const long long mod = 1000000007;//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cinchar s[100005];int vis[30];int main(){int i, j;while (~scanf("%s", s)){memset(vis, 0, sizeof(vis));int n = strlen(s);int l = 0, r = 0;int ans = 999999999;int num = 0;while (r < n || num == 26){while (r < n && num < 26){if (vis[s[r] - 'A'] == 0)num++;vis[s[r++] - 'A']++;}if (num == 26)ans = min(ans, r - l);if (vis[s[l] - 'A'] < 2)num--;vis[s[l++] - 'A']--;}if (ans != 999999999)printf("%d\n", ans);elseprintf("No Solution\n");}}
0 0
- 1127 最短的包含字符串
- 1127 最短的包含字符串
- 1127 最短的包含字符串
- 最短的包含字符串
- 51nod 1127 最短的包含字符串 (滑动窗口)
- 51NOD 1127 最短的包含字符串
- 51Nod-1127-最短的包含字符串
- 51NOD 1127 最短的包含字符串 尺取法
- 51nod 1127 最短的包含字符串(滑窗)
- 51NOD 1127 最短的包含字符串(尺取法)
- 51nod 1127 最短的包含字符串
- 51nod-【1127 最短的包含字符串】
- 51nod 1127 最短的包含字符串
- 51nod 1127 最短的包含字符串【尺取法】
- 51Nod 1127 最短的包含字符串
- 51nod 1127 最短的包含字符串 (尺取法)
- 51nod 1127 最短的包含字符串
- 51Nod 1127 最短的包含字符串 (尺取
- Codeforces 660D Number of Parallelograms
- 简单二叉树的层次遍历
- 策略模式(Strategy Pattern)
- PCA主成分分析
- Oracle数据库--实用操作(5)过程,函数,程序包
- 1127 最短的包含字符串
- 山东省第一届ACM省赛 B SDUT 2152 Balloons(简单的BFS)
- Java集合框架复习之规则集Set-LinkedHashSet(四)
- 事件 信号量 互斥锁 临界区总结
- Problem I: 冒泡排序法排序
- Convolutional Neural Networks卷积神经网络 (该博主一系列都很好)
- Hibernate ORM映射:基于主键的一对一
- hdu 1160 FatMouse's Speed【dp】
- jsp页面中的$(param.xxxxx)