#P15538. [CCC 2026 J3] Creative Candy Consumption
[CCC 2026 J3] Creative Candy Consumption
Description
Ngoc and Minh devised a creative way to eat candy that comes in three different colours: red, green, and blue.
They begin by arranging some coloured candies into a line. Then, the candy at the front of Ngoc's line is compared to the candy at the front of Minh's line. If both candies are the same colour, then Ngoc and Minh each eat the candy at the front of their own line. If the candies are different colours, then the person with the winning candy eats the losing candy, and the winning candy stays at the front of its line.
- Red candy wins against green candy
- Green candy wins against blue candy
- Blue candy wins against red candy
This process of comparing and eating candy repeats until there is at least one empty line of candy. When that happens, if one person still has candy left in their line, then that person eats all of their leftover candy.
Your job is to determine how much candy each person eats.
Input Format
The first line of input contains a sequence of letters, representing Ngoc's line of candy. The second line of input contains a sequence of letters, representing Minh's line of candy. Each letter will be an uppercase , , or representing the colours red, green, and blue,respectively. The first letter in each sequence represents the colour of the candy at the front of that person's line. (There will always be at least one letter in each sequence.)
Output Format
There will be two lines of output.
On the first line, output the number of candies Ngoc eats. On the second line, output the number of candies Minh eats.
RRR
RGBB
2
5
Hint
Explanation of Output for Sample Input
| Candy Lines | Description |
|---|---|
| Ngoc: | Both people have red candy at the front of their lines. Ngoc eats her red candy and Minh eats his red candy. |
| Minh: | ^ |
So far, Ngoc has eaten candy and Minh has eaten candy.
| Candy Lines | Description |
|---|---|
| Ngoc: | Ngoc's red candy wins against Minh's green candy. Ngoc eats Minh's green candy. |
| Minh: | ^ |
So far, Ngoc has eaten candy and Minh has eaten candy.
| Candy Lines | Description |
|---|---|
| Ngoc: | Minh's blue candy wins against Ngoc's red candy. Ngoc eats Minh's red candy. |
| Minh: | ^ |
So far, Ngoc has eaten candy and Minh has eaten candy.
| Candy Lines | Description |
|---|---|
| Ngoc: | Minh's blue candy wins against Ngoc's red candy. Ngoc eats Minh's red candy. |
| Minh: | ^ |
So far, Ngoc has eaten candy and Minh has eaten candy.
| Candy Lines | Description |
|---|---|
| Ngoc: | Ngoc's line of candy is empty,so the process ends. Minh eats his remaining blue candies. |
| Minh: | ^ |
In total, Ngoc eats candies and Minh eats candies.
The following table shows how the available marks are distributed:
| Marks | Description | Bounds |
|---|---|---|
| Ngoc and Minh each have one candy. | and | |
| Either Ngoc's line will empty first, or both lines will empty at the same time. Ngoc and Minh could have many candies. | and | |
| Ngoc and Minh could have many candies. | ||
| Ngoc and Minh could have an absurd amount of candy. | and |
京公网安备 11011102002149号