Corona Virus Spread

Submit solution

Points: 15
Time limit: 1.0s
Memory limit: 256M

Problem type

Indeed, this task as well is about coronavirus :D.

In our simulator, we will represent the population by a string of lowercase characters. Also, we represent infected people with a lowercase character 'c'.

All initially infected people (the c's) will then start infecting the other character, and any infected character will die instantly (except those initially infected). However, the c's will only infect those to their left one a day, and of course, cannot infect an already infected person (another character c). This goes on every day until there is no other person is infected and dead.

Your task is, given a string of lowercase characters that represent the initial population of our simulator, find the number of days until no other person is infected, and the representation of our population after the end of the virus spread.

Input Specification

The first line of the input contains \(1 \le T \le 10\), the number of test cases.

T lines follow, each contains a string \(1 \le |s| \le 100\) with lower case letters, where |s| denotes the length of the string s.

Output Specification

For each test case, output the number of days until the virus will no longer spread followed by the representation of our population after the virus stops spreading.

Sample Input


Sample Output

0 azuz
0 corona
5 c
4 corona
4 ccorona


  • In the 1st sample, nobody is infected initially.
  • In the 2nd sample, only the first person is infected, thus the virus will not spread to any other person.
  • In the 3d sample, the last person is infected
  • In the 4rd sample, the c right after stop will eat all the 4 letters before it.
  • In the 5th sample, in the first day the leftmost c will eat p and the second one will eat o. Then the left c will eat the remaining characters of stop in the remaining 3 days.


  • 0
    code06  commented on Oct. 23, 2020, 4:20 p.m.

    In the input we have stopcorona and stopcocorona. And in the output they both output 4 days, even though stopcocorona has an additional o to infect. stopcocorona should output 5, shouldn't it?

    • 0
      aymanrs  commented on Oct. 23, 2020, 5:39 p.m.

      read the problem carefully. instead of infecting the others think about 'c's eating the others.