首页 > 代码库 > zju 2886

zju 2886

 

 

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

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

 

 

 

#include<iostream>using namespace std;#include<cstring>#include<cstdio>int main(){    int n,i,j,sum;    char a[1005];    while(cin>>n)    {        getchar();        for(i=0;i<n;i++)        {    cin>>a;            sum=1;            if(strlen(a)==1){ cout<<1<<a[0]<<endl;continue;}            for(j=1;j<strlen(a);)            {    while(a[j]==a[j-1]&&a[j]) {sum++;j++;}                if(a[j]!=a[j-1])                {    cout<<sum<<a[j-1];                    sum=1;                    }                if(a[j])                 {    if(a[j+1]==0) cout<<sum<<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[1005];
while(cin>>n)
{
getchar();
for(i=0;i<n;i++)
{ cin>>a;
sum=1;
if(strlen(a)==1){ cout<<1<<a[0]<<endl;continue;}
for(j=1;j<strlen(a);)
{ while(a[j]==a[j-1]&&a[j]) {sum++;j++;}
if(a[j]!=a[j-1])
{ cout<<sum<<a[j-1];
sum=1;
}
if(a[j]) 
{ if(a[j+1]==0) cout<<sum<<a[j];
j++;
}
}
cout<<endl;
}
}
return 0;
}
 
 
 
 
 
#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   {    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
   {
    cout<<sum<<s[i];
    sum=1;
   }
  }
  cout<<endl;
 }
 return 0;
}