Look and say 源码分析:
- #include <iostream>
- #include <fstream>
- #include <string>
- // each subsequent element is defined from the
- //previous one by "verbally"
- //For exam the string 122344111 can be descibled as
- //"one 1,twp 2,one 1,one 3,twp 4,three 1.
- using namespace std;
- int main(int argc,char *argv[])
- {
- //ifstream cin("aaa.txt");
- string s,t;
- int n;
- cin>>n;
- for(int i=0;i<n ;i++)
- {
- cin>>s;
- int c=0;
- t=s[0];
- int temp =0;
- for(int j=0;j<s.size();j++)
- {
- if(s[j]==t[0])
- {
- temp++;
- if(j==s.size()-1)
- {
- printf("%d%c",temp,t[0]);
- }
- }
- else
- {
- printf("%d%c",temp,t[0]);
- t[0]=s[j];
- temp =1 ;
- if(j==s.size()-1)
- {
- printf("%d%c",temp,t[0]);
- }
- }
- }
- cout<<endl;
- }
- return 0;
- }