s01串

code

#include<iostream>
#include<cstring>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int i, n;
	char sa[10000], sb[10000];

	cin >> n;
	sa[0] = '0', sa[1] = sb[0] = '\0';

	while (n--) {
		for (i = 0; '\0' != sa[i]; ++i) {
			if ('0' == sa[i]) {
				strcat(sb, "1");
			} else if ('1' == sa[i]) {
				strcat(sb, "01");
			}
		}
		strcpy(sa, sb);
		sb[0] = '\0';
	}
	cout << sa;
	return 0;
}

Q

试题 算法训练 s01串
     
资源限制
时间限制:1.0s   内存限制:256.0MB
问题描述
  s01串初始为"0"
  按以下方式变换
  0变1,1变01
输入格式
  1个整数(0~19)
输出格式
  n次变换后s01串
样例输入
3
样例输出
101
数据规模和约定
  0~19
posted @ 2022-02-25 10:20  ethon-wang  阅读(24)  评论(0编辑  收藏  举报