LUCKY STRING(微软校招)
题目描述
A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Given a string consisting of only lower case letters , output all its lucky non-empty substrings in lexicographical order. Same substrings should be printed once.
输入描述:
a string consisting no more than 100 lower case letters.
输出描述:
output the lucky substrings in lexicographical order.one per line. Same substrings should be printed once.
示例1
输入
复制
aabcd
输出
复制
a
aa
aab
aabc
ab
abc
b
bc
bcd
c
cd
d
题意:若一个串的某个子串中元素集合的个数是一个斐波那契数,则它就是幸运串,以字典序输出一个串中的所有幸运串。
思路:数据温暖,set + 暴力 + 预处理数值小于26的斐波那契表。
#include<bits/stdc++.h>using namespace std;set<int> jj;void init(){vector<int> a;a.push_back(1);a.push_back(1);jj.insert(1);int i = 2;while(a[i-1] + a[i-2] <= 26){int doll = a[i-1] + a[i-2];jj.insert(doll);a.push_back(doll);++i;}}int main(){char s[110];set<string> v;gets(s);init();for(int i = 0 ; s[i] ; ++ i){string ss = "";set<char> SET;ss += s[i];v.insert(ss);SET.insert(s[i]);for(int j = i + 1 ; s[j] ; ++ j){ss += s[j];SET.insert(s[j]);if(jj.count(SET.size()))v.insert(ss);}}set<string> :: iterator it = v.begin();while(it != v.end()){cout << *it << endl;it++;}}
LUCKY 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,有关斐波那契的题目都在此了
解决方案: int _tmain(int argc,_TCHAR* argv[]) {size_t fib[] = {1,2,3,5,8,13,21,34};string str,tempstr;ci ...
- 微软校招2015 Beautiful String
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 We say a string is beautiful if it has the equal amount of 3 ...
- 2016微软校招笔试题
标题 A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. ...
- LUCKY STRING
题目描述 A string s is LUCKY if and only if the number of different characters in s is a fibonacci numbe ...
- 微软校招笔试题#1092 : Have Lunch Together详解以及源码分析
#1092 : Have Lunch Together 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Everyday Littile Hi and Little Ho ...
最新文章
- 吴裕雄 python 神经网络——TensorFlow实现AlexNet模型处理手写数字识别MNIST数据集...
- php $start_date-sub(,PHP DateTime类常用方法总结
- configparser logging
- vue放大缩小div_vue 放大缩小 svg 图形(原理类似整个列表更新)
- CentOS 7 安装Docker
- 详解TCP和UDP数据段的首部格式
- oracle linux下数据迁移到不同服务器
- 航空运输行业:优质民营航司的黄金期才刚刚开始-20210106.PDF
- 51nod1770 数数字 规律
- 阿拉伯数字 转换 中文大写
- Hrbust 1162 魔女 【dp】
- 虚拟机VMware Workstation安装使用教程
- Fabric 1.0源代码分析(23)LevelDB(KV数据库)
- 经典0-1背包问题(C++解决代码优化版本)
- hightCharts制作三维立体图
- c语言双边滤波算法,浅析bilateral filter双边滤波器的理解
- 统计元音字母——输入一个字符串,统计处其中元音字母的数量。更复杂点的话统计出每个元音字母的数量。
- 微信视频号几点发布最好?看的人最多?
- EOS系列 - EOS发行Token
- HTML基础知识(八)——H5新增选择器