hdu 1020_Encoding(水题)
2014-05-25 10:02
441 查看
题目链接:clink here~~
题目大意是给出一连串单词,输出连续且相同字母的次数,次数为1的不输出次数。
如果有更简洁的代码,欢迎贴出交流。
题目大意是给出一连串单词,输出连续且相同字母的次数,次数为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"); } }
如果有更简洁的代码,欢迎贴出交流。
相关文章推荐
- hdu 1020 Encoding(水题)
- HDU 1020 Encoding 字符串 水题
- HDU1020 ZOJ2478 Encoding【水题】
- hdu1020 - Encoding
- HDU 1020 Encoding 字符串
- HDU 1020:Encoding
- hdu 1020 Encoding
- HDU 1020 Encoding 典型的字符串的压缩
- HDU 1020 - Encoding
- HDU-1020-Encoding,题意不清,其实很水~~
- HDU-1020-Encoding(水题,但题目意思容易搞错,英语的问题)
- hdu 1020 Encoding
- hdu 1020 Encoding
- HDU 1020 Encoding
- HDU 1020 Encoding (String)
- HDU 1020 Encoding
- HDU 1020 Encoding
- HDU 1020 Encoding
- hdu 1020 Encoding
- 【HDU 1020】Encoding 水