最短的包含字符串
来源:互联网 发布:下载头像的软件 编辑:程序博客网 时间:2024/05/23 05:09
给出一个字符串,求该字符串的一个子串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 <string>#include <string.h>using namespace std;int nums[26];void fun(string &input){ int len = input.length(); memset(nums, 0, sizeof(nums)); int count = 0; int left = 0; int right = 0; int result = len+1; while (right < len) { char cur = input[right]; if (nums[cur-'A'] == 0) { nums[cur-'A'] = 1; count++; } else { nums[cur-'A']++; } if (count == 26) {while (nums[input[left]-'A'] > 1){nums[input[left]-'A']--;left++;} int temp = right - left + 1; if (temp < result) { result = temp; } } right++; } if (result < len+1) { cout << result << endl; return; } cout << "No Solution" << endl;}int main(){ string input; cin >> input; fun(input); return 0;}
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 最短的包含字符串 (尺取
- wc命令
- 三次握手和四次挥手
- .net framwork 4.0安装总结
- Java学习笔记 Day03
- hive的metastore的选择
- 最短的包含字符串
- 机器学习中常用的矩阵求导公式
- [TensorFlow]入门学习笔记(2)-卷积神经网络mnist手写识别
- python计算机视觉和机器学习所需包(全)
- java多线程(一) 之 简介
- 很外没有写文章了
- Linux /etc/profile文件详解
- Easyui 在dialog中加载datagrid,并实现可拖放行(drag and drop rows)
- 图片上传并保存到数据库以及显示图片