zoukankan      html  css  js  c++  java
  • 转换字符串、插入字符的个数

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    
    #define MAXCOUNT 2*100
    
    char *transformation(char* str)
    {
        int len=strlen(str);
        char *buf=new char[len+1];
        
        char *p=str;
        char *q=p+1;
        int count=1;
        while(*q)
        {
            if(*p==*q)
            {
                count++;
                p++;
                q++;
            }else{
                itoa(count,buf,10);
                int nbits=strlen(buf);
                strcat(buf,q);
                *q=0;
                strcat(str,buf);
                q+=nbits;
                p=q;
                q=p+1;
                count=1;
            }
        }
        itoa(count,buf,10);
        strcat(str,buf);
        delete []buf;
        buf=NULL;
        return str;
    }
    
    int main()
    {
        char str[MAXCOUNT];
        printf("please input a string:");
        scanf("%s",&str);
        char *pstr=transformation(str);
        printf("after transformation:%s
    ",pstr); 
        return 0;
    }
    不犯罪盗版→提高自我技术
  • 相关阅读:
    SED{shell三剑客awk,sed,grep}
    AWK{shell三剑客awk,sed,grep}
    面试汇总
    shell脚本
    redis主从
    haproxy
    grafana
    zabbix
    lnmp
    shell 基础
  • 原文地址:https://www.cnblogs.com/zoudajia/p/6270657.html
Copyright © 2011-2022 走看看