Algorithm question: compress arbitrary strings and compress strings with Algorithms

Source: Internet
Author: User

Algorithm question: compress arbitrary strings and compress strings with Algorithms

// Input a string on the keyboard. // Compile a character string compression program to compress the repeated characters in the character string and output the compressed character string. /* For example, input AABBCC, and output 2A2B2C; input,..., and output 3, 2 .. */# Include <iostream> # include <string. h> # include <stdlib. h> using namespace std; void Grial (char * src) {char * Pnext = src; char * Prve = src; // If I select it, modify it on the original string, use the speed pointer to avoid extra space. Char * p = Prve; int count = 0; while (* Pnext! = '\ 0') {char ch = * Pnext; while (ch = * Pnext) {count ++; Pnext ++ ;} char * s = new char [count]; itoa (count, s, 10); count = 0; while (* s) {* Prve = * s; Prve ++; s ++;} * Prve ++ = ch;} * Prve = '\ 0';} int main () {char cinbuff [255]; cin> cinbuff; grial (cinbuff); cout <cinbuff <endl; return 0 ;}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.