Back
Close

String Annihilation

Statement

 Goal

In the spirit of particles and anti-particles, let's define characters and anti-characters as lower case and upper case characters respectively. As we all know particles meeting anti-particles annihilates each other and produce energy. In a string, an anti-character annihilates a character if they are adjacent and in the process release 1 unit of energy.

baACCcB → b(aA)C(Cc)B → bCB + 2 energy units

Given a string of characters, annihilate characters until a stable string is reached and record the energy released. A stable string is a string where no annihilation can occur.
Input
One line:
string consisting of only upper and lowercase letters between a-z.
Output
On two separate lines:
the remaining string after annilhilation
units of energy released
Constraints
string length is less than or equal to 255
Example
Input
aAaAa
Output
a
2

Game modes
Fastest, Shortest

Test cases
One letter Test
Input
aAaAa
Output
a 2

One letter Validator
Input
BbBbBbB
Output
B 3

One pass Test
Input
aABbEeeEFfAa
Output
6

One pass Validator
Input
FAaEefFFfKkF
Output
FF 5

Telescoping Test
Input
heAbCDeFfEdcBallo
Output
hello 6

Double telescope Validator
Input
oneaBCDdcbAtwoAbcdEeDCBathree
Output
onetwothree 9

Stable Test
Input
AAAbaaa
Output
AAAbaaa 0

Stable Validator
Input
AAbaaBaabA
Output
AAbaaBaabA 0

Messy Test
Input
REaABCbBcDdbeFfEsSeR
Output
RR 9

Messy Validator
Input
DcbBaABbCdIdCCBaAAabccD
Output
I 11

Large and random Test
Input
cbbbbcBAcbBCcBBAABAcbBaABacBbccbbaABBaCbbABbaBcCcAbAaBBBacbBCBCbCaCAacaAcAbbBAaAbaBacCbAaBAcAAaACCbAaCCcBbcaBacAccBaBBAAacAbbAabcababbcBAAcAAAbbABcAccccccCBCACbbbCabABCAaBCCAACCCbaCaCcabaAacCaccABacAcCbbCBaAbcBBCbBacaCBcaaaaABACcBaABABbCcCAcaAbBCacccbBBCc
Output
cbbbbcBAcBBAABAcBacccaCbcABBaBCbCacAbAbaBcAACCbaBacAccBaBBAcAbbbcababbcBAAcAAAbbABcAcccccBCACbbbCabABCBCCAACCCbaCaabaaccABacACacaCBcaaaBABBAccB 56

Large and random Validator
Input
yYyxzXzYxYyXyyXxXZyzYyXXZxyYZYyXYzxZxYxXYxzZxXZzZZYzZZzXYYZzYzZzxzZzyXxyxYxXYzzxYyzXzYxXZZzZXxZXXzYXxyxXzXXXXYyZXxYyXzzYXXYxYzZxXZYxYxXyXXZZXzzYXxyxXYyXZxZXZzyXZZzyYyxYyxzxzzZYyxxzzzXyZxxxXzxYZZxZZXyxxyYyyzxxzZyzZXxzzxYxyXxYyYzzzxyzZxxXxxzxXYzXZyxXzZyyyXZ
Output
yxzXzyXZyzXXZxZXYzxZxYYxZZYXYYYzxzyyxYYzzxzXzYZZZXXzzXXXXZXzzYXXYxYZYXZZXzzXZxZXyXZyxxzxzxxzzzXyZxxzxYZZxZZXyxxyyzxxyzzxYxzzzxyxxxzYzXZyyyyXZ 57

Solution language

Solution

Stub generator input