hdu 1020

时间:2023-11-15 13:10:08

//自信满满地交上去~~but。。。超时了

#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std; int main()
{
char ch[],c;
int i,k,j;
cin>>i;
while(i)
{
cin>>ch;
for(k=;k<strlen(ch);)
{
if(ch[k]!=ch[k+])
{cout<<ch[k];k++;}
else
{
c=ch[k];
for(j=k;ch[k]&&ch[j]==c;j++);
cout<<j-k<<c;
k=j;
}
}
cout<<endl;
i--;
}
return ;
}

//于是。。。重来。。。orz
//这是借鉴大神的。。。。发现自己的思路好单一。。。。。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int main()
{
int n,i,cnt;
char str[];
cin >> n;
while(n--)
{
cin >> str;
for(i = ; str[i]!='\0';)
{
cnt = ;
while(str[i] == str[i+])
{
cnt++;
i++;
}
if(cnt == )
cout << str[i];
else
cout << cnt << str[i];
i++;
}
cout << endl;
} return ;
}