微软2016校园招聘在线笔试第二场 A Lucky Substrings
2015-04-25 11:13
357 查看
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
样例输入
样例输出
#include <iostream>
#include<cstring>
#include <algorithm>
using namespace std;
bool f(string s1,string s2)
{
if(s1<s2)return true;
else return false;
}
int m=0;
string ss[100000];
int judge[11]={0,1,2,3,5,8,13,21};
bool p1(string ss1){
for(int i1=0;i1<m;i1++)
if(ss1==ss[i1]){return 0;}
return 1;
}
bool p(string s2){
if(s2.length()==1)return 1;
int sum=0;
int n1=s2.length();
int a[26];
memset(a,0,sizeof(a));
for(int i=0;i<n1;i++){
if(a[s2[i]-'a']==0){a[s2[i]-'a']=1;sum++;}
}
for(int i=0;i<8;i++)
if(sum==judge[i])return 1;
return 0;
}
int main(){
string s;
cin>>s;
int n=s.length();
for(int i=0;i<n;i++){
int j=1;
while(s[i+j-1]==s[i+j-2]){
j++;
}
for(;j<n-i+1;j++){
string s1=s.substr(i,j);
if (p(s1)&&p1(s1))
ss[m++]=s1;
}
}
sort(ss,ss+m,f);
for(int i=0;i<m;i++)
cout<<ss[i]<<endl;
return 0;}
单点时限:1000ms
内存限制:256MB
描述
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.样例输入
aabcd
样例输出
a aa aab aabc ab abc b bc bcd c cd d 注意:aabcd是一个特殊的事例:
#include <iostream>
#include<cstring>
#include <algorithm>
using namespace std;
bool f(string s1,string s2)
{
if(s1<s2)return true;
else return false;
}
int m=0;
string ss[100000];
int judge[11]={0,1,2,3,5,8,13,21};
bool p1(string ss1){
for(int i1=0;i1<m;i1++)
if(ss1==ss[i1]){return 0;}
return 1;
}
bool p(string s2){
if(s2.length()==1)return 1;
int sum=0;
int n1=s2.length();
int a[26];
memset(a,0,sizeof(a));
for(int i=0;i<n1;i++){
if(a[s2[i]-'a']==0){a[s2[i]-'a']=1;sum++;}
}
for(int i=0;i<8;i++)
if(sum==judge[i])return 1;
return 0;
}
int main(){
string s;
cin>>s;
int n=s.length();
for(int i=0;i<n;i++){
int j=1;
while(s[i+j-1]==s[i+j-2]){
j++;
}
for(;j<n-i+1;j++){
string s1=s.substr(i,j);
if (p(s1)&&p1(s1))
ss[m++]=s1;
}
}
sort(ss,ss+m,f);
for(int i=0;i<m;i++)
cout<<ss[i]<<endl;
return 0;}
相关文章推荐
- Lucky Substrings 微软2016校园招聘在线笔试第二场
- 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings
- Numeric Keypad 微软2016校园招聘在线笔试第二场
- 微软2016校园招聘在线笔试第二场——Lucky Substrings
- 微软2016校园招聘在线笔试第二场
- Spring Outing 微软2016校园招聘在线笔试第二场
- 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings
- 题目3 : Spring Outing 微软2016校园招聘在线笔试第二场
- 微软2016校园招聘4月在线笔试 ABC
- [Hihocoder 1289] 403 Forbidden (微软2016校园招聘4月在线笔试)
- hihocoder: 1239 Fibonacci(微软2016校园招聘9月在线笔试)
- hihocoder 1290 -- 微软2016校园招聘4月在线笔试-3-Demo Day
- Demo Day (微软2016校园招聘4月在线笔试)
- 微软2016校园招聘4月在线笔试:Font Size
- 微软2016校园招聘在线笔试-Professor Q's Software
- hihocoder 1289 微软2016校园招聘4月在线笔试-2:403 Forbidden
- 微软2016校园招聘在线笔试题目-第一题 Magic Box
- 微软2016校园招聘在线笔试: [Islands Travel]
- 微软2016校园招聘4月在线笔试 hihocoder 1288 Font Size (模拟)
- hihocoder 1239 Fibonacci(微软2016校园招聘9月在线笔试)