1140 Look-and-say Sequence

中文版

1084 外观数列

 1 #include<iostream> 
 2 using namespace std;
 3 int main(){
 4     int d,n;
 5     cin>>d>>n;
 6     string ans;
 7     ans += d+'0';
 8     for(int i = 0; i < n-1;++i){
 9         string temp;
10         for(int j = 0; j < ans.size();++j){
11             int cnt = 1;
12             while(j+1 < ans.size()&& ans[j] == ans[j+1]){
13                 ++j;
14                 ++cnt;
15             }
16             temp += ans[j];
17             temp += cnt + '0';
18         }
19         ans = temp;
20     }
21     cout<<ans;
22     return 0;
23 }

 

posted @ 2020-03-14 18:06  tangq123  阅读(124)  评论(0编辑  收藏  举报