HDU1020 - Encoding (模拟)

来源:互联网 发布:爰淘宝商城 编辑:程序博客网 时间:2024/05/22 03:46

题目链接

  • 思路
  • 代码

思路

这道题刚开始一直没读懂题意,读懂题意就很好做了,他是将相同的字符转化成数字+字母。例如 ABBA 变成 A2BA

代码

#include <cstdio>#include <cstring>using namespace std;char text[10010];int main(){    int n, count;    scanf("%d", &n);    while(n--)    {        scanf("%s", text);        count = 1;        for(int i=0; i<strlen(text); i++)        {            if(text[i]==text[i+1]) count++;            else            {                if(count==1) printf("%c", text[i]);                else printf("%d%c", count, text[i]);                count = 1;            }        }        printf("\n");    }}
0 0
原创粉丝点击