Lucky Substrings HihoCoder
来源:互联网 发布:网络搞笑剧有哪些 编辑:程序博客网 时间:2024/06/03 23:42
题目
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.
INPUT
A string consisting no more than 100 lower case letters.
OUTPUT
Output the lucky substrings in lexicographical order, one per line. Same substrings should be printed once.
sample input
aabcd
sample output
a
aa
aab
aabc
ab
abc
b
bc
bcd
c
cd
d
使用了c++的字符串处理函数
ac代码
#include <cstdio>#include <cstring>#include <cmath>#include <set>#include <string>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;const int mod = 1e9+7;int a[26];int main(){ set<string> t; string s,cur; cin>>s; int len = s.size(); //j是长度 i是位置 for (int i = 0;i < len; ++i){ for (int j = 1;j+i <= len; ++j){ cur = s.substr(i,j); int lh = cur.size(); memset(a,0,sizeof(a)); for (int k = 0;k < lh; ++k){ a[cur[k]-'a'] = 1; } int cnt = 0; for (int k = 0;k < 26; ++k){ if (a[k]) cnt++; } if (cnt==1||cnt==2||cnt==3||cnt==5||cnt==8||cnt==13||cnt==21){ t.insert(cur); } } } set<string>::iterator it = t.begin(); while (it!=t.end()){ cout<<*it<<endl; it++; } return 0;}
阅读全文
0 0
- hihocoder Lucky Substrings
- hihoCoder - 1152 - Lucky Substrings
- hihocoder #1152 : Lucky Substrings
- Lucky Substrings HihoCoder
- hihoCoder week 84 P1 : Lucky Substrings 【dp】
- Lucky Substrings
- Lucky Substrings微软在线测试
- hihoCoder_W84 Lucky Substrings(基础做法)
- Lucky Substrings 微软2016校园招聘在线笔试第二场
- lucky
- 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings
- Substrings
- Substrings
- Substrings
- Substrings
- Substrings
- Substrings
- Substrings
- 深度学习中BP(Backpropagation)算法的工作流程
- CoordinatorLayout的AppBarLayout和CollapsingToolbarLayout
- JDK的网络资源地址
- 30道经典面试题
- SQLSTATE[42S02]: Base table or view not found: 1146 Table 'blog.user' doesn't exist (SQL: select * f
- Lucky Substrings HihoCoder
- 共享锁和排他锁
- 元数据/MetaData
- JavaBean简介及使用
- 【C++】动态内存管理(五)使用STL容器进行大量的动态内存管理
- C++写实拷贝
- 191. Number of 1 Bits
- forHTTPHeaderField
- 单纯形引理