Look and say 源码分析

Look and say 源码分析:

Code:
  1. #include <iostream>   
  2. #include <fstream>   
  3. #include <string>   
  4. // each subsequent element is defined from the   
  5. //previous one by "verbally"   
  6. //For exam the string 122344111 can be descibled as   
  7. //"one 1,twp 2,one 1,one 3,twp 4,three 1.   
  8. using namespace std;   
  9.   
  10. int main(int argc,char *argv[])   
  11. {   
  12.     //ifstream cin("aaa.txt");   
  13.     string s,t;   
  14.     int n;   
  15.     cin>>n;   
  16.     for(int i=0;i<n ;i++)   
  17.     {   
  18.         cin>>s;   
  19.         int c=0;   
  20.         t=s[0];   
  21.         int temp =0;   
  22.         for(int j=0;j<s.size();j++)   
  23.         {   
  24.             if(s[j]==t[0])   
  25.             {   
  26.                 temp++;   
  27.                 if(j==s.size()-1)   
  28.                 {   
  29.                     printf("%d%c",temp,t[0]);   
  30.                 }   
  31.             }   
  32.             else  
  33.             {   
  34.                 printf("%d%c",temp,t[0]);   
  35.                 t[0]=s[j];   
  36.                 temp =1 ;   
  37.                 if(j==s.size()-1)   
  38.                 {   
  39.                     printf("%d%c",temp,t[0]);   
  40.                 }   
  41.             }   
  42.   
  43.         }   
  44.         cout<<endl;   
  45.     }   
  46.     return 0;   
  47. }   
  48.   
  49.   

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值