微软校招2015 Beautiful String
来源:互联网 发布:淘宝店尾页区域怎么改 编辑:程序博客网 时间:2024/06/05 06:04
- 样例输入
43abc4aaab6abccde3abb
- 样例输出
YESNOYES
NO
#include <stdio.h>#include <stdlib.h>bool IsBeautiful(char *str, int length) {if(str == NULL || length < 3)return false;char c[3];int count[3] = {0, 0, 0};int i = 0;for(int j = 0; j < 2; j++){if(i >= length)return false;c[j] = str[i];while(i < length && str[i] == c[j]){count[j]++;i++;}}for( ;i < length;) {c[2] = str[i];count[2] = 0;while(i < length && str[i] == c[2]) {count[2]++;i++;}if(c[0]+1 == c[1] && c[1]+1 == c[2] && count[0] >= count[1] && count[2] >= count[1]) {return true;}c[0] = c[1];c[1] = c[2];count[0] = count[1]; count[1] = count[2];}return false;}char buffer[10000005];int main(void) {int tests;int length;//freopen("beautiful_string.txt", "r", stdin);scanf("%d", &tests);while (tests--) {scanf("%d", &length);getchar();gets(buffer);if(IsBeautiful(buffer, length)) {printf("YES\n");}else {printf("NO\n");}} return 0;}
描述
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.
- 微软校招2015 Beautiful String
- 微软笔试题《Beautiful String》
- 微软2014校招笔试题-String reorder
- 2014----微软校招
- Beautiful String
- Beautiful String
- 微软2014实习生及校招秋令营技术类职位在线测试:1.String reorder
- 【2014校招】微软笔试
- 微软2014实习生及校招秋令营技术类职位在线测试:2.K-th string
- [微软苏州校招 Hihocoder] Disk Storage
- 微软2016校招笔试题
- 微软2017校招第一题
- 2016微软校招笔试题
- Beautiful String-连续字符串
- hihocoder Beautiful String
- 题目1 : Beautiful String
- hihoCoder 1061 Beautiful String
- hihocoder #1061 : Beautiful String
- Load Balance Tomcat with Nginx and Store Sessions in Redis
- 剑指offer--面试题4:替换空格--Java实现
- 【算法】16个无序数最多20次比较找到第二大的数
- 疯狂Java之学习笔记(4)---------------UML及面向对象
- Lazy<T>
- 微软校招2015 Beautiful String
- android intent
- 命令模式command
- x264参数介绍(二、分析和视频可用性信息)
- Jump Game
- Java之LinkedList详解
- SQL行列转换实例
- lua正则式
- Android数据库 之 SQLite数据库