鱼C论坛

 找回密码
 立即注册
查看: 1783|回复: 1

[已解决]求助一题C语言题目

[复制链接]
发表于 2017-12-4 14:52:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
想了好久还没想出来T_T
最佳答案
2017-12-9 11:12:29
本帖最后由 lyjlyj 于 2017-12-9 14:25 编辑
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define LEN 100
  4. int main()
  5. {
  6.         char array[LEN];
  7.         int count[LEN];
  8.         int i,is_one_ahead;
  9.         int tail;
  10.         while(gets(array)!=NULL)
  11.         {
  12.                 for(i=0;i<LEN;i++)
  13.                 {
  14.                         count[i]=0;
  15.                 }
  16.                 i=0;
  17.                 is_one_ahead=1;
  18.                 tail=-1;
  19.                 while(1)
  20.                 {
  21.                         if(array[i]!='\0')
  22.                         {
  23.                                 if(array[i]=='0'  &&  is_one_ahead == 1)
  24.                                 {
  25.                                         tail++;
  26.                                         is_one_ahead = 0;
  27.                                         count[tail]++;
  28.                                 }
  29.                                 else if(array[i]=='1'  &&  is_one_ahead ==0)
  30.                                 {
  31.                                         tail++;
  32.                                         is_one_ahead = 1;
  33.                                         count[tail]++;
  34.                                 }
  35.                                 else
  36.                                 {
  37.                                         count[tail]++;
  38.                                 }
  39.                                        
  40.                         }
  41.                         else
  42.                         {
  43.                                  break;
  44.                         }
  45.                         i++;
  46.                 }
  47.                 for(i=0;i<=tail;i++)
  48.                 i<tail?printf("%d ",count[i]):printf("%d\n",count[i]);
  49.         }
  50.         return 0;
  51. }

复制代码
P)_Z1@$3FB7DQW%I()_1KFK.png
VU92(S421%MR1%VMP7B}}]M.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-12-9 11:12:29 | 显示全部楼层    本楼为最佳答案   
本帖最后由 lyjlyj 于 2017-12-9 14:25 编辑
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define LEN 100
  4. int main()
  5. {
  6.         char array[LEN];
  7.         int count[LEN];
  8.         int i,is_one_ahead;
  9.         int tail;
  10.         while(gets(array)!=NULL)
  11.         {
  12.                 for(i=0;i<LEN;i++)
  13.                 {
  14.                         count[i]=0;
  15.                 }
  16.                 i=0;
  17.                 is_one_ahead=1;
  18.                 tail=-1;
  19.                 while(1)
  20.                 {
  21.                         if(array[i]!='\0')
  22.                         {
  23.                                 if(array[i]=='0'  &&  is_one_ahead == 1)
  24.                                 {
  25.                                         tail++;
  26.                                         is_one_ahead = 0;
  27.                                         count[tail]++;
  28.                                 }
  29.                                 else if(array[i]=='1'  &&  is_one_ahead ==0)
  30.                                 {
  31.                                         tail++;
  32.                                         is_one_ahead = 1;
  33.                                         count[tail]++;
  34.                                 }
  35.                                 else
  36.                                 {
  37.                                         count[tail]++;
  38.                                 }
  39.                                        
  40.                         }
  41.                         else
  42.                         {
  43.                                  break;
  44.                         }
  45.                         i++;
  46.                 }
  47.                 for(i=0;i<=tail;i++)
  48.                 i<tail?printf("%d ",count[i]):printf("%d\n",count[i]);
  49.         }
  50.         return 0;
  51. }

复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-28 14:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表