Home  >  Q&A  >  body text

php - C语言算法题-开灯问题 代码有点看不懂求大神指点?

巴扎黑巴扎黑2741 days ago563

reply all(3)I'll reply

  • 阿神

    阿神2017-04-18 10:35:11

    The code you circled is the statement that outputs the results. This means that there is no space before the first output number, and each subsequent number adds a space to the previous number.
    first is a flag bit. It is first assigned a value of 1 and is judged during the loop output. At this time, first=1, which is the first result output. Then print the result directly and set first to 0. Then print the subsequent output. At this time, first=0 (not the first number), then output a space first and then print the number.

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:35:11

    1 5 6 7 in the example is actually 1[space]5[space]6[space]7[space]

    If it is the first unfolded light (first is true), only modify the flag bit to false (do not output " ") and then output the number of the light. If it is not the first displayed light (judge whether it is the first displayed light) first has been set to 0), first output " " and then the number

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:35:11

    ....Isn’t this just to use spaces to divide the resulting numbers....
    Otherwise they would all be connected 1567

    reply
    0
  • Cancelreply