#abc322a. A - First ABC 2
A - First ABC 2
Score : points
问题描述
给定一个长度为 的字符串 ,其中包含字符 A
、B
和 C
。
寻找 ABC
首次作为连续子串出现在 中的位置。换句话说,找到满足以下所有条件的最小整数 。
- 。
- 从 中提取第 个到第 个字符得到的字符串是
ABC
。
如果 ABC
不在 中出现,则输出 -1
。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a string of length consisting of A
, B
, and C
.
Find the position where ABC
first appears as a (contiguous) substring in . In other words, find the smallest integer that satisfies all of the following conditions.
- .
- The string obtained by extracting the -th through -th characters of is
ABC
.
If ABC
does not appear in , print -1
.
Constraints
- is a string of length consisting of
A
,B
, andC
.
Input
The input is given from Standard Input in the following format:
Output
Print the position where ABC
first appears as a substring in , or -1
if it does not appear in .
Sample Input 1
8
ABABCABC
Sample Output 1
3
ABC
first appears in at the -rd through -th characters of . Therefore, the answer is .
Sample Input 2
3
ACB
Sample Output 2
-1
If ABC
does not appear in , print .
Sample Input 3
20
BBAAABBACAACABCBABAB
Sample Output 3
13
update @ 2024/3/10 01:41:47