hdu 1020_Encoding(水题)

来源:互联网 发布:淘宝网针织衫女 编辑:程序博客网 时间:2024/06/08 04:16

题目链接:clink here~~

题目大意是给出一连串单词,输出连续且相同字母的次数,次数为1的不输出次数。

#include <cstdio>#include <cstdlib> #include <vector>#include <iostream>using namespace std;struct str{    char a;    int counts;}Str[10000];int main(){     int n;     char a;     int start = 0;     int j;     bool exit;     bool begin;         scanf("%d",&n);     getchar();     while(n --)     {                  for(int i = 0; i < 10000; i++)         {             Str[i].counts = 0;            // Str[i].a = ' ';         }         start = 0;         while(scanf("%c",&a))         {             exit = false;             begin = false;             if(a == '\n')break;             if(start == 0)             {                 Str[start].a = a;                 Str[start].counts = 1;                  start++;                 begin = true;             }                          else               {                     if(a == Str[start - 1].a)                 {                     Str[start - 1].counts ++;                     exit = true;//printf("Str[%d].counts:%d\n",j,Str[j].counts);                 }             }             if(!begin && !exit)             {                 Str[start].a = a;                 Str[start].counts = 1;                  start ++;             }         }        // printf("start:%d\n",start);         for(j = 0; j < start; j ++)            if(Str[j].counts > 1)                 printf("%d%c",Str[j].counts,Str[j].a);             else                 printf("%c",Str[j].a);         printf("\n");     }}

如果有更简洁的代码,欢迎贴出交流。

0 0
原创粉丝点击