欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1674C.Infinite Replacement
Infinite Replacement
You are given a string , consisting only of Latin letters 'a', and a string , consisting of lowercase Latin letters.
In one move, you can replace any letter 'a' in the string with a string . Note that after the replacement string might contain letters other than 'a'.
You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.
Two strings are considered different if they have different length, or they differ at some index.
Input
The first line contains a single integer () — the number of testcases.
The first line of each testcase contains a non-empty string , consisting only of Latin letters 'a'. The length of doesn't exceed .
The second line contains a non-empty string , consisting of lowercase Latin letters. The length of doesn't exceed .
Output
For each testcase, print the number of different strings that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number.
Note
In the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.
In the second example, you can replace the second letter 'a' with "abc". String becomes equal to "aabc". Then the second letter 'a' again. String becomes equal to "aabcbc". And so on, generating infinitely many different strings.
In the third example, you can either leave string as is, performing zero moves, or replace the only 'a' with "b". String becomes equal to "b", so you can't perform more moves on it.
Samples
3
aaaa
a
aa
abc
a
b
1
-1
2
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |