• 微软2016校园招聘在线笔试第二场 A Lucky Substrings


    时间限制:10000ms
    单点时限: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;}

  • 相关阅读:
    luogu P1340 兽径管理
    luogu P2828 Switching on the Lights(开关灯)
    luogu P1462 通往奥格瑞玛的道路
    codevs 2596 售货员的难题
    luogu P1145 约瑟夫
    luogu P1395 会议
    luogu P1041 传染病控制
    luogu P1198 [JSOI2008]最大数
    codevs 1191 数轴染色
    [POJ1082]Calendar Game
  • 原文地址:https://www.cnblogs.com/lengxia/p/4455601.html
Copyright © 2020-2023  润新知