A given string consists of only lowercase letters a, B, and c. When two different consecutive letters appear, you can replace them with another letter.
If AB or ba appears consecutively, replace them with the letter c;
When an ac or ca appears consecutively, you can replace them with the letter B;
When bc or cb appears consecutively, you can replace them with the letter.
You can constantly follow this rule to replace it. Your goal is to make the final result string as short as possible and find the shortest length of the final result.
Input: string. It cannot exceed 200 characters in length and can only contain three lowercase letters (abc.
Output: Replace the string according to the above rules and the minimum length of the string is obtained.
For example:
Input cab and Output 2. Because we can change it to bb or cc.
Input bcab and Output 1. Although we can change it to aab-> ac-> B, we can also change it to bbb, but because the former is shorter, the output is 1.
#include <stdio.h> MAX 200 typedef String[ MAX + N(x) N_(x) N_(x) #x input( * unsigned min_len( * main( printf( unsigned min_len( * input( * puts( scanf(N(MAX) puts( }
len = strlen( s );
reduce( newstr , s , i1 );
newlen ;
newlen = min_len( newstr );
( newlen <=
unsigned min_len( * len = i = ( s[i] != && s[i+] != ( s[i] != s[i+ newlen = ( newlen < len = i ++ }
#include <stdio.h> #include <.h> MAX 200 typedef String[ MAX + N(x) N_(x) N_(x) #x input( * unsigned min_len( * reduce( * , * turn ( , main( printf( turn ( c1 , + + - c1 - reduce( * st , * st[i] = turn ( ss[i] , ss[i+ strcpy( st + i + , ss + i + unsigned min_len( * len = i = ( s[i] != && s[i+] != ( s[i] != s[i+ newlen = ( newlen < len = i ++ input( * puts( scanf(N(MAX) puts( }