怪盗KID


私信TA

用户名:dotcpp0774863

访问量:427

签 名:

一万年太久,只争朝夕。

等  级
排  名 1931
经  验 2513
参赛次数 0
文章发表 20
年  龄 19
在职情况 学生
学  校 哔哩哔哩
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include<stdio.h>
#include<string.h>
int main()
{   
    char str[100] = { 0 };
    int n;
    scanf_s("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf_s("%s", &str, (unsigned int)sizeof(str));
        int str_len = strlen(str);
        int cnt = 1;        //计数
        for (int j = 0; j < str_len; j++) {         //遍历字符
            
            if (str[j] == str[j + 1]) {
                cnt++;
            }
            if (str[j] != str[j + 1]) {     //只有当出现前一个与后一个不同时才会开始打印结果
                if (cnt > 1) { printf("%d", cnt); }
                printf("%c", str[j]);
                cnt = 1;        //初始化
            }

        }
        printf("\n");
    }
    return 0;
}


 

0.0分

1 人评分

  评论区

  • «
  • »