文章

3

粉丝

98

获赞

2

访问

1.0k

头像
字符串压缩 题解:
P1718 兰州大学2017年机试题
发布于2024年2月7日 14:11
阅读数 297

#include<stdio.h>
#include<stdlib.h>

int main() {
    char a[100];
    gets(a);
    int position = 0;
    int times = 0;
    while(a[position] != '\0') {
        if (a[position] == a[position + 1]) {
            times ++;
        } else {
            if (times == 0) {
                printf("%c", a[position]);
            } else {
                printf("%c%d", a[position], times + 1);
            }
            times = 0;
        }
        position ++;
    }

    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发