Codeforces round #256 (Div. 2) B (448b) Suffix Structures

Source: Internet
Author: User


The meaning is to convert the first string to the second string. Two operations are supported, one is to delete, and the other is to change the character position.

Simple string operation !!

The AC code is as follows:

#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#define  M 50010#define inf 100000000using namespace std;char a[1005],b[1005];int la,lb;bool  automaton(){    int i=0,j=0,flag=0;    while(a[i]!='\0')    {        if(a[i]==b[j])        {            i++;            j++;            flag++;        }        else        {            i++;        }    }    if(flag==lb) return true;    return false;}int main(){    int i,j;    int c[500],d[500];    cin>>a;    cin>>b;    la=strlen(a);    lb=strlen(b);    if(lb>la)    {        printf("need tree\n");        return 0;    }    if(la==lb)    {        memset(c,0,sizeof c);        memset(d,0,sizeof d);        for(i=0;i<la;i++)            c[a[i]]++;        for(i=0;i<lb;i++)            d[b[i]]++;        int ans=0;        for(i='a';i<='z';i++)            if(c[i]==d[i])            ans++;        if(ans==26)        {            printf("array\n");            return 0;        }    }    else if(automaton())    {        printf("automaton\n");        return 0;    }        memset(c,0,sizeof c);        memset(d,0,sizeof d);        int anss=0;        for(i=0;i<lb;i++)            d[b[i]]++;        for(i=0;i<la;i++)            c[a[i]]++;            for(i='a';i<='z';i++)                if(d[i]!=0)                anss++;        int an=0;        for(i='a';i<='z';i++)            if(c[i]>=d[i]&&d[i]!=0)                an++;        //cout<<an<<" "<<anss<<endl;        if(an==anss)        {            printf("both\n");            return 0;        }        printf("need tree\n");    return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.