QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#20818. חיפוש והחלפה

Statistics

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.