hdu 1020(模拟)

//模拟
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

char str[10001];

void solve() {
int l = strlen(str);
int c = 1;
char ch = str[0];
for (int i=1; i<l; ++i) {
if (ch == str[i]) ++c;
else {
if (c > 1) printf ("%d%c", c, ch);
else printf ("%c", ch);
c = 1;
ch = str[i];
}
}
if (c > 1) printf ("%d%c\n", c, ch);
else printf ("%c\n", ch);
return ;
}

int main() {
int t;
scanf ("%d", &t);
while (t--) {
scanf ("%s", str);
solve();
}
return 0;
}

 

你可能感兴趣的:(HDU)