Character string compression-solutions for programmers

Source: Internet
Author: User

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(  }


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.