您的位置:首页 > 其它

hdu 1020_Encoding(水题)

2014-05-25 10:02 441 查看
题目链接: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");

}
}


如果有更简洁的代码,欢迎贴出交流。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: