蓝桥杯训练-S01串

标题:S01串
s01串初始为"0"
  按以下方式变换
  0变1,1变01
输入格式
  1个整数(0~19)
输出格式
  n次变换后s01串
样例输入
3
样例输出
101
数据规模和约定
  0~19

#include <iostream>
#include <string>
using namespace std;
int main(){
	int n;
	string s="0";
	cin>>n;
	while(n--){
		for(int i=0;i<s.length();i++){
			if(s[i]=='0'){
				s[i]='1';
				
			}else if(s[i]=='1'){
				s.insert(i,"0");
				i++;
			}
		}
	}
	cout<<s<<endl;
	return 0;
}
发布了33 篇原创文章 · 获赞 18 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/lz970704/article/details/104987794