Balanced Substring
题意翻译
**题目描述**
给一个长度为 $n$($1\le n \le50$)仅由 a 和 b 组成的字符串(字符的编号由 $1$ 到 $n$),找到任意一对 $l$ 和 $r$($1\le l<r \le n$),使得 $l$ 到 $r$ 的连续子串中 a 和 b的数量相同。
**输入格式**
第一行为一个正整数 $t$($1\le t\le1000$),表示有 $t$ 组数据。
接下来 $2\times t$ 行,输入每组数据。
每组数据一共两行。第一行为一个正整数 $n$,表示字符串长度;第二行为一个长度为 $n$ 仅由 a 和 b 组成的字符串。
**输出格式**
对于每组数据,输出一行两个数 $l$ 和 $r$。若找不到满足条件的 $l$ 和 $r$,输出两个 $-1$。(两个数之间用空格隔开,两组数据之间需换行)
Translated by @银杉水杉秃杉
2021.9.13
题目描述
You are given a string $ s $ , consisting of $ n $ letters, each letter is either 'a' or 'b'. The letters in the string are numbered from $ 1 $ to $ n $ .
$ s[l; r] $ is a continuous substring of letters from index $ l $ to $ r $ of the string inclusive.
A string is called balanced if the number of letters 'a' in it is equal to the number of letters 'b'. For example, strings "baba" and "aabbab" are balanced and strings "aaab" and "b" are not.
Find any non-empty balanced substring $ s[l; r] $ of string $ s $ . Print its $ l $ and $ r $ ( $ 1 \le l \le r \le n $ ). If there is no such substring, then print $ -1 $ $ -1 $ .
输入输出格式
输入格式
The first line contains a single integer $ t $ ( $ 1 \le t \le 1000 $ ) — the number of testcases.
Then the descriptions of $ t $ testcases follow.
The first line of the testcase contains a single integer $ n $ ( $ 1 \le n \le 50 $ ) — the length of the string.
The second line of the testcase contains a string $ s $ , consisting of $ n $ letters, each letter is either 'a' or 'b'.
输出格式
For each testcase print two integers. If there exists a non-empty balanced substring $ s[l; r] $ , then print $ l $ $ r $ ( $ 1 \le l \le r \le n $ ). Otherwise, print $ -1 $ $ -1 $ .
输入输出样例
输入样例 #1
4
1
a
6
abbaba
6
abbaba
9
babbabbaa
输出样例 #1
-1 -1
1 6
3 6
2 5
说明
In the first testcase there are no non-empty balanced subtrings.
In the second and third testcases there are multiple balanced substrings, including the entire string "abbaba" and substring "baba".