#abc310c. C - Reversible
C - Reversible
Score : points
问题描述
有 根棍子,每根棍子上粘着若干个球。每个球上都写有一个小写英文字母。
对于每个 ,第 根棍子上的球所写的字母由字符串 表示。具体来说,第 根棍子上粘着的球的数量就是字符串 的长度 ,而 是从棍子一端开始的球上的字母序列。
当一根棍子从一端开始的球上的字母序列等于另一根棍子从一端开始的字母序列时,这两根棍子被认为是相同的。更形式化地讲,对于整数 和 在闭区间 到 内,如果满足 等于 或其反转,则认为第 根和第 根棍子是相同的。
请输出这 根棍子中有多少种不同的棍子。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are sticks with several balls stuck onto them. Each ball has a lowercase English letter written on it.
For each , the letters written on the balls stuck onto the -th stick are represented by a string . Specifically, the number of balls stuck onto the -th stick is the length of the string , and is the sequence of letters on the balls starting from one end of the stick.
Two sticks are considered the same when the sequence of letters on the balls starting from one end of one stick is equal to the sequence of letters starting from one end of the other stick. More formally, for integers and between and , inclusive, the -th and -th sticks are considered the same if and only if equals or its reversal.
Print the number of different sticks among the sticks.
Constraints
- is an integer.
- is a string consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
6
a
abc
de
cba
de
abc
Sample Output 1
3
- =
abc
equals the reversal of =cba
, so the second and fourth sticks are considered the same. - =
abc
equals =abc
, so the second and sixth sticks are considered the same. - =
de
equals =de
, so the third and fifth sticks are considered the same.
Therefore, there are three different sticks among the six: the first, second (same as the fourth and sixth), and third (same as the fifth).
update @ 2024/3/10 08:48:04