微软校招2015 Beautiful String
-
描述
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相关推荐
- 微软校招编程题Beautiful String的状态机解法
昨天碰巧看到一道微软校招的编程题,题目大意如下: 如果一个字符串包括三组或者更多组的连续升序字母,每组长度相等,那么我们就称这个字符串是Beautiful String如下是一些Beautiful S ...
- 我是如何从双非本科到拿到微软校招offer的?
2021-12-26 个人情况 本人女,江苏人,本科就读于南京某双非一本,现就读于北京理工大学,今年上半年开始找实习,后来拿到了微软北京SDE的暑期实习offer,并于九月份成功转正到苏州微软. 写这 ...
- 2014 微软校招笔试答案 编程题
上午参加完微软校招笔试,最后编程题的代码,仅供参考 #include <iostream> using namespace std; struct Node { Node *next; ...
- 微软校招来喽 | 内推名额等待优秀的你
微软2023届秋季校园招聘 | 内推名额等待优秀的你 微软2023届秋季校园招聘开始啦!我是本次校招推星官,小伙伴们赶快准备中英文简历,然后找我内推吧. 此次招聘Software Engineer,P ...
- LUCKY STRING(微软校招)
题目描述 A string s is LUCKY if and only if the number of different characters in s is a fibonacci numbe ...
- 残差学习,152层网络,微软夺冠2015 ImageNet计算机视觉识别挑战
美国东部时间2015年12月10日,微软亚洲研究院视觉计算组在2015 ImageNet计算机识别挑战赛中凭借深层神经网络技术的最新突破,以绝对优势获得图像分类.图像定位以及图像检测全部三个主要项目的 ...
- 微软发布2015年7月安全公告 安全狗提醒及时修复
2019独角兽企业重金招聘Python工程师标准>>> 7月15日消息,微软"周二补丁日"如期发布2015年7月安全更新公告,此次共包含14枚补丁,4枚为&quo ...
- hihocoder 1061.Beautiful String
题目链接:http://hihocoder.com/problemset/problem/1061 题目意思:给出一个不超过10MB长度的字符串,判断是否里面含有一个beautiful strings ...
- 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 ...
最新文章
- [转载] 信息系统项目管理师考试论文写作要点
- Python最抢手、Go最有前途,7000位程序员揭秘2019软件开发现状
- oracle logminer全解析
- 3分钟解决MySQL 1032 主从错误(转)
- 小型Web应用扫描工具Grabber
- 【opencv】丁达尔效应
- PDF:解决从PDF中复制文字时出现的空方框问题
- CO-ACT物料分类账
- Linux vi 行尾 ctrl,linux中vi使用技巧常用技巧和高级替换
- python安装os模块_centeros安装python3过程
- GDT、LDT、IDTR、TR
- 【第三方授权登录】微信授权登录
- RadASM资源链接错误RC2104及找不到resource.h解决方案
- 【18日】foobox 1.0.1 (foobar2000 CUI配置)
- oracle同义词6,Oracle同义词
- python寻找完全平方数,Python3 完全平方数案例
- raspberry pi pico|爷青回!在raspberry pi pico上玩nes游戏(2)(开源树莓派pico NES模拟器)-搭建pico开发环境
- html style
- 流程控制之顺数结构和选择结构
- Oracle关于分组小计再合计