Pro.ID22162 TitleGenerate String Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22162 AC0 Submit0 Ratio- 时间&空间限制描述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 Sample Output 1 Source 样例输入2 样例输出1 作者 |