22162_GenerateString

2022-5-16 18:21| 发布者: Hocassian| 查看: 25| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506164098800-Problem List-采集的数据-后羿采集器.html

Pro.ID

22162

Title

Generate String

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22162

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    ZZZ wants to generate a sequence of characters starting from an empty string using the following method.

    First, S0 = "" is an empty string.

    For a generated string Sk, he can chooses any position to split Sk into two continuous string Sk1 and Sk2. Notice that either Sk1 or Sk2 may be empty. Then he can add a string Sk0, which consists of only a single kind of character, to concatenate them. So Sk+1 = Sk1 + Sk0 + Sk2.

    Your task is to help ZZZ to generate a given string using minimum steps.

    Take the following example.

    S = "aabbaab"

    S0 = ""

    S1 = "aaaa"

    S2 = "aabbaa"

    S3 = "aabbaab"

    输入

    The first line of input there is one integer T ( T ≤ 100 ), giving the number of test cases in the input. Each test case contains a line with string S. The length of S is no more than 200. S is made up of only lowercase letters.

    输出

    Description

    ZZZ wants to generate a sequence of characters starting from an empty string using the following method.

    First, S0 = "" is an empty string.

    For a generated string Sk, he can chooses any position to split Sk into two continuous string Sk1 and Sk2. Notice that either Sk1 or Sk2 may be empty. Then he can add a string Sk0, which consists of only a single kind of character, to concatenate them. So Sk+1 = Sk1 + Sk0 + Sk2.

    Your task is to help ZZZ to generate a given string using minimum steps.

    Take the following example.

    S = "aabbaab"

    S0 = ""

    S1 = "aaaa"

    S2 = "aabbaa"

    S3 = "aabbaab"

    Input

    The first line of input there is one integer T ( T ≤ 100 ), giving the number of test cases in the input. Each test case contains a line with string S. The length of S is no more than 200. S is made up of only lowercase letters.

    Output

    For each test case, output the number of minimum steps.

    Sample Input

    2
    a
    aabbaab

    Sample Output

    1
    3

    Source

    样例输入

    2
    a
    aabbaab

    样例输出

    1
    3

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部