codeforces 448 B. Suffix Structures

简介:

题目链接:http://codeforces.com/contest/448/problem/B
题目大意:已知字符串a,b,要把a转换成b。如需删除输出automaton,如需交换输出array,都需要输出both,不可能成功输出need tree。
提示:用两个数组记一下26个字母的个数,在比较字母个数的大小,也就是先找need tree的时候

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
char a[105];
char b[105];
int main()
{
    int suma[26]={0};
    int sumb[26]={0};
    cin>>a>>b;
    int lena=strlen(a);
    int lenb=strlen(b);
    for(int i=0; i<lena; i++)
        suma[a[i]-'a']++;
    for(int i=0; i<lenb; i++)
        sumb[b[i]-'a']++;
    int arr=0;
    int aut=0;
    int f=0;
    for(int i=0; i<26; i++)
    {
        if(suma[i] < sumb[i])
        {
            puts("need tree");
            f=1;
            break;
        }
        if(suma[i]>sumb[i])
            aut=1;
    }
    if(f)
        return 0;
    int pos=0;
    for(int i=0; i<lenb; i++)
    {
        int flag=0;
        for(int j=pos; j<lena; j++)
        {
            if(a[j] == b[i])
            {
                pos=j+1;
                flag=1;
                break;
            }
        }
        if(flag == 0)
        {
            arr=1;
            break;
        }
    }
    if(arr == 1 && aut == 1)
        puts("both");
    else if(arr == 1)
        puts("array");
    else
        puts("automaton");
    return 0;
}
目录
相关文章
|
6月前
codeforces 285C - Building Permutation
题目大意是有一个含n个数的数组,你可以通过+1或者-1的操作使得其中的数是1--n中的数,且没有重复的数。 既然是这样的题意,那么我就应该把原数组中的数尽量往他最接近1--n中的位置放,然后求差绝对值之和,但有多个数,怎么使他们和最小,这样就要对其进行排序了,直接按大小给它们安排好位置,然后计算。
18 0
|
8月前
UVa11565 - Simple Equations
UVa11565 - Simple Equations
35 0
|
8月前
UVa11714 - Blind Sorting
UVa11714 - Blind Sorting
36 0
|
12月前
Educational Codeforces Round 113 (Rated for Div. 2)A. Balanced Substring
Educational Codeforces Round 113 (Rated for Div. 2)A. Balanced Substring
60 0
|
Unix Python
LeetCode 71. Simplify Path
给定文件的绝对路径(Unix下的路径)字符串,简化此字符串。
62 0
LeetCode 71. Simplify Path
|
机器学习/深度学习
AtCoder Beginner Contest 215 E - Chain Contestant (状压dp)
AtCoder Beginner Contest 215 E - Chain Contestant (状压dp)
87 0
AtCoder Beginner Contest 214 F - Substrings(subsequence DP)
AtCoder Beginner Contest 214 F - Substrings(subsequence DP)
75 0
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
76 0