题解 | #s01串#

s01串

https://ac.nowcoder.com/acm/problem/14356

思路

小常识:string有加法,给定一个新的字符串和旧的字符串,旧字符串每一位替换加到新字符串,递归n次答案就出来了。

代码

#include<bits/stdc++.h>
using namespace std;

int n;

void fc(string str,int cnt){
    if(cnt==n){
        cout<<str<<endl;
        return;
    }
    string tmp="";
    for(int i=0;i<str.length();i++){
        if(str[i]=='0') tmp=tmp+"1";
        if(str[i]=='1') tmp=tmp+"01"; 
    }
    fc(tmp,cnt+1);
}

int main(){
    scanf("%d",&n);
    string s="0";
    fc(s,0);
    return 0;
}
全部评论

相关推荐

02-16 01:39
南昌大学 Java
重剑Ds:感觉不太可能 后端都减飞了 根本不缺人
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务