时间限制: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
#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;
}

微软校招2015 Beautiful String相关推荐

  1. 微软校招编程题Beautiful String的状态机解法

    昨天碰巧看到一道微软校招的编程题,题目大意如下: 如果一个字符串包括三组或者更多组的连续升序字母,每组长度相等,那么我们就称这个字符串是Beautiful String如下是一些Beautiful S ...

  2. 我是如何从双非本科到拿到微软校招offer的?

    2021-12-26 个人情况 本人女,江苏人,本科就读于南京某双非一本,现就读于北京理工大学,今年上半年开始找实习,后来拿到了微软北京SDE的暑期实习offer,并于九月份成功转正到苏州微软. 写这 ...

  3. 2014 微软校招笔试答案 编程题

    上午参加完微软校招笔试,最后编程题的代码,仅供参考 #include <iostream> using namespace std; struct Node { Node *next;   ...

  4. 微软校招来喽 | 内推名额等待优秀的你

    微软2023届秋季校园招聘 | 内推名额等待优秀的你 微软2023届秋季校园招聘开始啦!我是本次校招推星官,小伙伴们赶快准备中英文简历,然后找我内推吧. 此次招聘Software Engineer,P ...

  5. LUCKY STRING(微软校招)

    题目描述 A string s is LUCKY if and only if the number of different characters in s is a fibonacci numbe ...

  6. 残差学习,152层网络,微软夺冠2015 ImageNet计算机视觉识别挑战

    美国东部时间2015年12月10日,微软亚洲研究院视觉计算组在2015 ImageNet计算机识别挑战赛中凭借深层神经网络技术的最新突破,以绝对优势获得图像分类.图像定位以及图像检测全部三个主要项目的 ...

  7. 微软发布2015年7月安全公告 安全狗提醒及时修复

    2019独角兽企业重金招聘Python工程师标准>>> 7月15日消息,微软"周二补丁日"如期发布2015年7月安全更新公告,此次共包含14枚补丁,4枚为&quo ...

  8. hihocoder 1061.Beautiful String

    题目链接:http://hihocoder.com/problemset/problem/1061 题目意思:给出一个不超过10MB长度的字符串,判断是否里面含有一个beautiful strings ...

  9. K-th Beautiful String CodeForces - 1328B(二分+数学)

    For the given integer n (n>2) let's write down all the strings of length n which contain n−2 lett ...

最新文章

  1. [转载] 信息系统项目管理师考试论文写作要点
  2. Python最抢手、Go最有前途,7000位程序员揭秘2019软件开发现状
  3. oracle logminer全解析
  4. 3分钟解决MySQL 1032 主从错误(转)
  5. 小型Web应用扫描工具Grabber
  6. 【opencv】丁达尔效应
  7. PDF:解决从PDF中复制文字时出现的空方框问题
  8. CO-ACT物料分类账
  9. Linux vi 行尾 ctrl,linux中vi使用技巧常用技巧和高级替换
  10. python安装os模块_centeros安装python3过程
  11. GDT、LDT、IDTR、TR
  12. 【第三方授权登录】微信授权登录
  13. RadASM资源链接错误RC2104及找不到resource.h解决方案
  14. 【18日】foobox 1.0.1 (foobar2000 CUI配置)
  15. oracle同义词6,Oracle同义词
  16. python寻找完全平方数,Python3 完全平方数案例
  17. raspberry pi pico|爷青回!在raspberry pi pico上玩nes游戏(2)(开源树莓派pico NES模拟器)-搭建pico开发环境
  18. html style
  19. 流程控制之顺数结构和选择结构
  20. Oracle关于分组小计再合计

热门文章

  1. cba比赛比分预测_今晚五场CBA比赛预测
  2. kubernetes 禁用虚拟内存 swapoff -a ----- 顺便复习sed 命令
  3. C语言 一元二次方程
  4. 【读书笔记】西行漫记
  5. 【榜单】Recode全球科技100人:华裔马化腾、黄仁勋、柳青、王兴、陆奇等5人上榜...
  6. 除烟超猛的油烟机,还有智慧内核加持,云米AI烟灶套装体验
  7. chatgpt使用什么语言写的
  8. C++反射机制的实现
  9. 输入年月日,获得下个月的同一天,如果该天不存在,则顺延一天
  10. 第四届-模拟智能灌溉系统