CF2166A.Same Difference
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s of length n, consisting of lowercase letters.
In one operation, you can select an integer i such that 1≤i<n and change si into si+1.
What is the minimum number of operations needed to make every character the same? It can be proved that this is always possible.
给你一个长度为 n 的字符串 s,其中仅包含小写字母。
在一次操作中,你可以选择一个整数 i,满足 1≤i<n,并将 si 修改为 si+1。
使字符串中所有字符都相同的最少操作次数是多少?可以证明该目标总能实现。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤20). The description of the test cases follows.
The first line of each test case contains an integer n (2≤n≤100) — the length of the string.
The following line contains a string s of length n, consisting of lowercase letters.
It is guaranteed that the sum of n over all test cases does not exceed 100.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤20)。随后是测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤100)—— 字符串的长度。
接下来的一行包含一个长度为 n 的字符串 s,由小写字母组成。
保证所有测试用例的 n 之和不超过 100。
输出格式
For each test case, output a single integer — the minimum number of operations needed to make every character the same.
对于每个测试用例,输出一个整数——使所有字符相同所需的最少操作次数。
输入输出样例
输入#1
5 3 qwq 2 aa 4 test 5 abbac 6 abcabc
输出#1
1 0 2 4 4
说明/提示
In the first test case, you can change s2 to s3 using 1 operation to reach the goal.
In the third test case, you can change s3 to s4 and then change s2 to s3, using 2 operations in total. It can be proved that the answer is not less than 2.
在第一个测试用例中,你可以通过 1 次操作将 s2 改为 s3,从而达成目标。
在第三个测试用例中,你可以先将 s3 改为 s4,再将 s2 改为 s3,总共需要 2 次操作。可以证明答案不小于 2。
输入解题思路,AI测评打分。不知道怎么写?