hdu1020 Encoding
http://acm.hdu.edu.cn/showproblem.php?pid=1020
过了的就是好孩子。。。。。。。。
1 #include<stdio.h> 2 #include<math.h> 3 #include<string.h> 4 #include<stdlib.h> 5 #include<iostream> 6 #include<queue> 7 using namespace std; 8 const int N=10005; 9 char a[N],b[N]; 10 int main() 11 { 12 //freopen("in.txt","r",stdin); 13 int n; 14 cin>>n; 15 while(n--) 16 { 17 memset(a,0,sizeof(a)); 18 memset(b,0,sizeof(b)); 19 scanf("%s",a); 20 int len=strlen(a); 21 if(len==1) 22 { 23 printf("%s\n",a); 24 continue; 25 } 26 int t=0,count=0; 27 for(int i=0;i<len;i++) 28 { 29 if(a[i+1]!='\0') 30 { 31 if(a[i+1]==a[i]) 32 { 33 count++;//数数 34 continue; 35 } 36 } 37 if(count!=0) 38 { 39 count+=1; 40 int temp=count,k=0; 41 while(temp!=0)//计算位数 42 { 43 temp/=10; 44 k++; 45 } 46 t--; 47 int h=k; 48 while(k) 49 { 50 b[t+k]=count%10+'0';//从后赋值,123先将3赋值到b 51 count/=10; 52 k--; 53 } 54 t+=h+1;//指向 55 } 56 b[t++]=a[i]; 57 count=0; 58 } 59 b[t]='\0'; 60 printf("%s\n",b); 61 } 62 return 0; 63 }