HDU1020 Encoding 简单队列

简单队列

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<queue>
 4 using namespace std;
 5 int main()
 6 {
 7     int n;
 8     scanf("%d",&n);
 9     queue<char>q;
10     char ch,str[10010];
11     while(n--)
12     {
13         scanf("%s",&str);
14         for(int i=0;i<strlen(str);i++)
15             q.push(str[i]);
16         ch=q.front();
17         int count=1;
18         while(!q.empty())
19         {
20             q.pop();
21             if(ch==q.front()) count++;
22             else
23             {
24                 if(count>1) printf("%d",count);
25                 printf("%c",ch);
26                 ch=q.front();
27                 count=1;    
28             }                         
29         }
30         printf("
");             
31     }  
32 }
原文地址:https://www.cnblogs.com/lqquan/p/3693818.html