hihocoder Beautiful String
2015-08-12 22:31
197 查看
题目1 : Beautiful String
时间限制:10000ms单点时限:1000ms
内存限制:256MB
描述
We say a string is beautiful if it has the equal amount of 3 or more continuous letters (in increasing order.)Here are some example of valid beautiful strings: "abc", "cde", "aabbcc", "aaabbbccc".
Here are some example of invalid beautiful strings: "abd", "cba", "aabbc", "zab".
Given a string of alphabets containing only lowercase alphabets (a-z), output "YES" if the string contains a beautiful sub-string, otherwise output "NO".
输入
The first line contains an integer number between 1 and 10, indicating how many test cases are followed.For each test case: First line is the number of letters in the string; Second line is the string. String length is less than 10MB.
输出
For each test case, output a single line "YES"/"NO" to tell if the string contains a beautiful sub-string.
提示
Huge input. Slow IO method such as Scanner in Java may get TLE.样例输入
4 3 abc 4 aaab 6 abccde 3 abb
样例输出
YES NO YES NO
判断一个字符串中有没有 符合要求的字符串 要求出现至少出现三个连续的字母 且每个字母的个数相等
形如 aabbcc
直接统计每个字母连续出现的个数 因为只是要判断存不存在 所以直接判断有没有三个就好 因为最前最后的字母是可以丢弃的 所以要求两边的个数比中间大于等于
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <algorithm> #include <string.h> #include <string> #include <vector> #include <queue> #define MEM(a,x) memset(a,x,sizeof a) #define eps 1e-8 #define MOD 10009 #define MAXN 1000010 #define MAXM 100010 #define INF 99999999 #define ll __int64 #define bug cout<<"here"<<endl #define fread freopen("ceshi.txt","r",stdin) #define fwrite freopen("out.txt","w",stdout) using namespace std; int Read() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int x = 0; while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x; } void Print(int a) { if(a>9) Print(a/10); putchar(a%10+'0'); } char ch[MAXN]; int a[MAXN],num[MAXN]; int main() { //fread; int tc; scanf("%d",&tc); while(tc--) { int len; scanf("%d",&len); getchar(); scanf("%s",ch); MEM(a,0); MEM(num,0); int y=0; a[y]=ch[0]-'a'+1; num[y]=1; for(int i=1;i<len;i++) { if((ch[i]-'a'+1)==a[y]) { num[y]++; } else { y++; a[y]=ch[i]-'a'+1; num[y]=1; } } int flag=0; for(int i=0;i<=y-2;i++) { if(a[i]+1==a[i+1]&&a[i]+2==a[i+2]&&num[i]>=num[i+1]&&num[i+2]>=num[i+1]) { flag=1; break; } } if(flag) puts("YES"); else puts("NO"); } return 0; }
相关文章推荐
- Exception in thread "main" java.lang.NoClassDefFoundError: Demo (wrong name: com/zhangyun/Demo)解决办法
- 函数调用
- hdu 5335 Walk Out(暴力)
- UIPageControl
- python网络编程(2)
- HDU 3336 Count the string (KMP next数组运用——统计前缀出现次数)
- 谷歌被墙,如何给谷歌浏览器添加迅雷下载插件
- Path Patterns 和 Patterns with Placeholders
- extern 关键字的使用 《程序员的自我修养》·笔记
- linux 做 wifi 热点(俗称AP)
- UI 06 _ 7种手势
- linux/Ubantu 解压缩jdk失败的解决方案
- 集合的规则与使用简介
- file上传按钮替换以及解决IE浏览器隐藏file按钮不能上传文件问题
- HDU 1019
- [Vijos]P1788 第k大
- 《机器学习系统设计》之应用scikit-learn做文本分类(上)
- Codeforces Round #200 (Div. 2) C. Rational Resistance(脑洞思维)
- STL容器相关内容
- Hbase的java api操作小结