首页 > 代码库 > zju 2478

zju 2478

 

-#include <iostream>using namespace std;int main(int argc, char *argv[]){ int n,i,sum; string s; cin>>n; while(n--) {  cin>>s;  for(i=0,sum=1;s[i];i++)  {   if(s[i]==s[i+1]) sum++;   else   {    if(sum==1)     cout<<s[i];    else     cout<<sum<<s[i];    sum=1;   }  }  cout<<endl; } return 0;}
View Code

 

-#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
 int n,i,sum;
 string s;
 cin>>n;
 while(n--)
 {
  cin>>s;
  for(i=0,sum=1;s[i];i++)
  {
   if(s[i]==s[i+1]) sum++;
   else
   {
    if(sum==1)
     cout<<s[i];
    else
     cout<<sum<<s[i];
    sum=1;
   }
  }
  cout<<endl;
 }
 return 0;
}

 

 

 

 

#include<iostream>using namespace std;#include<cstring>#include<cstdio>int main(){    int n,i,j,sum;    char a[105];    cin>>n;    getchar();    for(i=0;i<n;i++)    {    cin>>a;        sum=1;        for(j=1;j<strlen(a);)        {    while(a[j]==a[j-1]&&a[j]) {sum++;j++;}            if(a[j]!=a[j-1])            {    if(sum==1) cout<<a[j-1];                else                 {    cout<<sum<<a[j-1];}                sum=1;                }            if(a[j])             {    if(a[j+1]==0) cout<<a[j];                j++;            }        }        cout<<endl;    }    return 0;}
View Code
#include<iostream>
using namespace std;
#include<cstring>
#include<cstdio>
int main()
{
int n,i,j,sum;
char a[105];
cin>>n;
getchar();
for(i=0;i<n;i++)
{ cin>>a;
sum=1;
for(j=1;j<strlen(a);)
{ while(a[j]==a[j-1]&&a[j]) {sum++;j++;}
if(a[j]!=a[j-1])
{ if(sum==1) cout<<a[j-1];
else 
{ cout<<sum<<a[j-1];}
sum=1;
}
if(a[j]) 
{ if(a[j+1]==0) cout<<a[j];
j++;
}
}
cout<<endl;
}
return 0;
}