s01字符串---蓝桥杯

问题描述
  s01串初始为"0"
  按以下方式变换
  0变1,1变01
输入格式
  1个整数(0~19)
输出格式
  n次变换后s01串
样例输入
3
样例输出
101
数据规模和约定
  0~19
 
简单求解:
 1 #include<stdio.h>
 2 #include<string.h>
 3 
 4 int main()
 5 {
 6     char s[10000]={'0'};
 7     int num;
 8     int i,j,k;
 9     scanf("%d",&num);
10     for(i=0;i<num;i++)
11     {    char str[10000]={};
12         for(j=0;j<strlen(s);j++)
13         {
14             if(s[j]=='0')
15                 strcat(str,"1");
16             if(s[j]=='1')
17                 strcat(str,"01");
18         }
19         for(j=0;j<strlen(str);j++)
20         s[j]=str[j];    
21     }
22     printf("%s\n",s);         
23     return 0;
24 }

 

posted @ 2017-03-02 21:03  余小叙  阅读(442)  评论(0)    收藏  举报