zoukankan      html  css  js  c++  java
  • 字符串 (扫一遍 + 计数)

    A - AAAAA
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    Description

    Given a string containing only 'A' - 'Z', we could encode it using the following method: 

    1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string. 

    2. If the length of the sub-string is 1, '1' should be ignored. 
     

    Input

    The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 10000. 
     

    Output

    For each test case, output the encoded string in a line. 
     

    Sample Input

    2 ABC ABBCCC
     

    Sample Output

    ABC A2B3C
     

    小结:比赛时,题意理解错了,以为是扫完一遍后,再输出字母的个数,比如 BBAABB, 按我错误的code应该是输出 2A4B, 而实际应该是输出 2B2A2B。 赛后问了学长一下题意,10minAC了,郁闷。。。(写这个题是为提醒自己要认真读题,不能只看输入输出,就盲目敲) 


    #include<stdio.h>
    #include<string.h>
    int main()
    {
        int n, i, count=0;
        char a[10005];
        scanf("%d", &n);
        while(n--)
        {
            scanf("%s", a);
            int len = strlen(a);
            for(i=0; i<len; i++)
            {
                if(a[i] == a[i+1]) count++;
                else
                {
                    if(count == 0)  printf("%c", a[i]);
                    else  printf("%d%c", count+1, a[i]);
    
                    count = 0;
                }
            }
            printf("
    ");
        }
        return 0;
    }
    

    每天训练发现我比别人做的好慢,但是理解的更深刻,如果一开始学一个新知识点就搜模板,那么这样的人是走不远的,毕业之后带走的只有思维,什么荣誉,奖杯都已经不重要了。
  • 相关阅读:
    【新阁教育】爱普生机器人建立工具坐标系教程
    BPF CO-RE 示例代码解析
    gRPC Load Balancing
    Linux Clone函数
    高性能 Nginx HTTPS 调优
    内网渗透测试:内网横向移动基础总结
    Python 运算符
    华为云-容器引擎CCE-部署Nginx应用
    华为云-云容器引擎(CCE)-高危操作及解决方案
    周杰伦新歌《说好不哭》上线,程序员哭了......
  • 原文地址:https://www.cnblogs.com/6bing/p/3931242.html
Copyright © 2011-2022 走看看