Lucky Substrings
- 样例输入
-
aabcd
- 样例输出
-
a
-
aa
-
aab
-
aabc
-
ab
-
abc
-
b
-
bc
-
bcd
-
c
-
cd
-
d
-
思路:暴力枚举。26以内斐波那契数打下表就可以了。用set去重排序。复杂度O(n*n*n);
-
我用前缀和,感觉并没有优化。
-
1 #include<stdio.h> 2 #include<algorithm> 3 #include<iostream> 4 #include<string.h> 5 #include<stdlib.h> 6 #include<math.h> 7 #include<cstdio> 8 #include<queue> 9 #include<stack> 10 #include<map> 11 #include<set> 12 using namespace std; 13 char cou[200]; 14 int fei[30]; 15 int flag[30]; 16 char dd[200]; 17 set<string>my; 18 set<string>::const_iterator it; 19 typedef struct pp 20 { 21 int al[26]; 22 pp() 23 { 24 memset(al,0,sizeof(al)); 25 } 26 } ss; 27 28 int main(void) 29 { 30 int n,i,j,k,p,q; 31 fei[1]=1; 32 fei[2]=1; 33 for(i=3; i<30; i++) 34 { 35 fei[i]=fei[i-1]+fei[i-2]; 36 if(fei[i]>=26) 37 { 38 break; 39 } 40 } 41 int zz=i; 42 for(i=1; i<zz; i++) 43 flag[fei[i]]=1; 44 while(scanf("%s",cou)!=EOF) 45 { 46 my.clear(); 47 ss ak[200]; 48 int l=strlen(cou); 49 int cnt=0; 50 ak[cnt].al[cou[0]-'a']++; 51 for(i=1; i<l; i++) 52 { 53 ak[i].al[cou[i]-'a']++; 54 for(j=0; j<26; j++) 55 { 56 ak[i].al[j]+=ak[i-1].al[j]; 57 } 58 } 59 int yy[26]; 60 for(i=0; i<l; i++) 61 { 62 for(int s=0; s<26; s++) 63 { 64 yy[s]=ak[i].al[s]; 65 } 66 int ans=0; 67 for(int s=0; s<26; s++) 68 { 69 if(yy[s]) 70 { 71 ans++; 72 } 73 74 } 75 if(flag[ans]) 76 { 77 memset(dd,0,sizeof(dd)); 78 int z=0; 79 int s; 80 for( s=0; s<=i; s++) 81 { 82 dd[z++]=cou[s]; 83 } 84 my.insert(dd); 85 86 } 87 } 88 for(i=0; i<l; i++) 89 { 90 for(j=i+1; j<l; j++) 91 { 92 for(int s=0; s<26; s++) 93 { 94 yy[s]=ak[j].al[s]-ak[i].al[s]; 95 } 96 int ans=0; 97 for(int s=0; s<26; s++) 98 { 99 if(yy[s])100 {101 ans++;102 }103 104 }105 if(flag[ans])106 {107 memset(dd,0,sizeof(dd));108 int z=0;109 int s;110 for( s=i+1; s<=j; s++)111 {112 dd[z++]=cou[s];113 }114 my.insert(dd);115 }116 }117 }118 for(it=my.begin(); it!=my.end(); it++)119 {120 cout<<*it<<endl;121 }122 }123 return 0;124 }
描述
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.
Lucky Substrings的更多相关文章
- hihocoder 1152 Lucky Substrings
#1152 : Lucky Substrings 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if t ...
- 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if the number of different ch ...
- hihocoder #1152 Lucky Substrings 【字符串处理问题】strsub()函数+set集合去重
#1152 : Lucky Substrings时间限制:10000ms单点时限:1000ms内存限制:256MB描述A string s is LUCKY if and only if the nu ...
- Lucky String
Lucky String -- 微软笔试 标签(空格分隔): 算法 A string s is LUCKY if and only if the number of different charact ...
- 【每天一道算法题】Lucky String
A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Gi ...
- lucky 的 时光助理(2)
lucky小姐说:昨天晚上他喝醉了,发消息说他想我了,说他后悔了. 我很惊讶. 我问lucky:你们很久都没有联系, 突然说... 你怎么想. 没错,'他'就是lucky的前男友. lucky看着我, ...
- lucky 的 时光助理
2017年的lucky小姐,厌倦了现在的工作,她觉得这些的工作对于她而言不具备挑战性,她在迷茫春节过后该如何选择, 这里是距她走出校门整整一年的时光. lucky小姐从开发走向了实施,目的是想周游这个 ...
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- ZOJ3944 People Counting ZOJ3939 The Lucky Week (模拟)
ZOJ3944 People Counting ZOJ3939 The Lucky Week 1.PeopleConting 题意:照片上有很多个人,用矩阵里的字符表示.一个人如下: .O. /|\ ...
随机推荐
- 03 Windows安装Java环境
Java环境安装 使用微信扫码关注微信公众号,并回复:"Java环境",免费获取下载链接! 1.卸载(电脑未装此程序,跳过此过程) 找到电脑上面的控制面板 找到这两个文 ...
- 第三个基础框架 — springMVC — 更新完毕
1.什么是springMVC? 还是老规矩,百度百科一下 这里面说了一堆废话,去官网瞄一下 官网网址:https://docs.spring.io/spring-framework/docs/curr ...
- Netty之Channel*
Netty之Channel* 本文内容主要参考**<<Netty In Action>> ** 和Netty的文档和源码,偏笔记向. 先简略了解一下ChannelPipelin ...
- 【leetcode】15. 3 Sum 双指针 压缩搜索空间
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i ...
- 简化版chmod
我们知道对文件访问权限的修改在Shell下可通过chmod来进行 例如 可以看到v.c文件从无权限到所有者可读可写可执行.群组和其他用户可读可执行 chmod函数原型 int chmod(const ...
- Kotlin 学习(2)
属性和字段 1.声明属性 Kotlin中可以使用var关键字声明可变属性,或者用val关键字声明只读属性,属性的类型在后面,变量名在前面,中间加冒号和空格. public class Address ...
- oracle(创建数据库对象)
1 --创建数据库 2 --1.SYSDBA系统权限 3 startup:--启动数据库. 4 shutdown:--关闭数据库. 5 alter database[mount]|[open]|[ba ...
- 【Python】【Basic】【数据类型】运算符与深浅拷贝
运算符 1.算数运算: 2.比较运算: 3.赋值运算: 4.逻辑运算: 5.成员运算: 三元运算 三元运算(三目运算),是对简单的条件语句的缩写. # 书写格式 result = 值1 if 条件 ...
- 30个类手写Spring核心原理之MVC映射功能(4)
本文节选自<Spring 5核心原理> 接下来我们来完成MVC模块的功能,应该不需要再做说明.Spring MVC的入口就是从DispatcherServlet开始的,而前面的章节中已完成 ...
- pipeline 共享库
目录 一.简介 二.共享库扩展 共享库使用 共享库结构 pipeline模板 一些小问题 三.共享库例子 使用公共变量 使用共享库的src方法 使用共享库的vars方法 四.插件实现pipeline ...