QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 256 MB Toplam puan: 100

#20818. بحث واستبدال

İstatistikler

تستخدم Bessie أحدث وأفضل ابتكار في تحرير النصوص، miV! تريد تحويل سلسلة إدخال من حروف إنجليزية كبيرة وصغيرة فقط إلى سلسلة إخراج. بضغطة واحدة يُستبدل كل ظهور لحرف $c_1$ بحرف آخر $c_2$. مثلًا تتحول $\texttt{aAbBa}$ عند اختيار $c_1$ = a و$c_2$ = B إلى $\texttt{BAbBB}$.

Bessie مشغولة، فلكل حالة من $T$ ($1\le T\le 10$) حالات مستقلة احسب أقل ضغطات لتحويل الإدخال للإخراج المطلوب.

الإدخال

يحوي السطر الأول عدد الحالات المستقلة $T$.

أزواج الأسطر $T$ التالية تعطي الإدخال والإخراج بنفس الطول، من A–Z أوa–z. مجموع أطوال كل السلاسل لا يتجاوز $10^5$.

الإخراج

لكل حالة اطبع أقل ضغطات، أو $-1$ إذا استحال التحويل.

أمثلة

الإدخال 1

4
abc
abc
BBC
ABC
abc
bbc
ABCD
BACD

الإخراج 1

0
-1
1
3

ملاحظة

الإدخال الأول يساوي الإخراج، فلا ضغطات مطلوبة.

الثاني مستحيل، فلا يمكن تغيير $\texttt{B}$ واحدة إلى $\texttt{A}$ مع إبقاء الأخرى $\texttt{B}$.

الثالث بتغيير $\texttt{a}$ إلى $\texttt{b}$.

الأخير هكذا: $\texttt{ABCD} \rightarrow \texttt{EBCD} \rightarrow \texttt{EACD} \rightarrow \texttt{BACD}$.

المهام الفرعية

  • الإدخالات 2–6: طول كل سلسلة لا يتجاوز $50$.
  • الإدخالات 7–9: الحروف الصغيرة $\texttt{a}$ إلى $\texttt{e}$ فقط.
  • الإدخالات 10–15: لا قيود إضافية.

مؤلف المسألة: Benjamin Qi

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.