Mirko purchased a new microprocessor. Unfortunately, he soon learned that many of his programs that he wrote for his old processor didn't work on the new processor.
Deep inside the technical documentation for both processors, he found an explanation. In order to work faster, the new processor imposes certain constraints on the machine code of programs, constraints that never existed on the previous model.
The machine code of a processor consists of instructions that are executed sequentially. Each instruction uses a byte of memory. Also, instructions can have zero or more parameters, each of which uses an additional byte of memory. In machine code, parameters immediately follow an instruction. When formatted as text, machine code instructions are uppercase letters, while parameters are lowercase letters. For example:
A b c b B c c C D e f g h
This program consists of four instructions; the first takes three parameters, the second two, the third none and the fourth takes four parameters. The program uses 13 bytes of memory.
The new processor model fetches memory in four-byte chunks so each instruction must start at a memory address that is divisible by four (the first byte in memory is address 0). To achieve that, we can insert NOP (no operation) instructions into the old program, instructions that do nothing and are not limited to memory locations divisible by four. The above program, adapted to run on the new processor, can look like this:
A b c b B c c NOP C NOP NOP NOP D e f g h
The instructions A, B, C and D are now at memory locations 0, 4, 8 and 12, which satisfies the processor's constraints.
Write a program that determines the smallest number of NOP instructions that need to be inserted for the given program to work on the new processor model.
input Abcd output 0 input EaEbFabG output 5 input AbcbBccCDefgh output 4
출처:coci/2008-2009/regional