"Blue Bridge Cup" basic exercise: 01 Strings

Source: Internet
Author: User

Problem description

For a 01-string length of 5 bits, each bit can be 0 or 1, a total of 32 possible. The first few of them are:

00000

00001

00010

00011

00100

Please output these 32 kinds of 01 strings in order from small to large.

Input format this question is not entered. Output format output 32 rows, in order from small to large in each row a length of 5 01 strings. Sample Output 00000
00001
00010
00011
< The following sections omit > Experience: This topic reminds me of the idea of using an integer array to hold a large number first, each time it starts with the first element and then adjusts. For each element in the array does not overflow, use while () to resolve.
1# include <stdio.h>2 intMainvoid)3 {4 inta[5]={0};5 inttemp;6 intTimes ;7 inti;8printf"00000\n");9  for(times=1; times<= to; times++)Ten { OneI=0; Aa[i]+=1; -      while(a[i]>=2) -     { thetemp=a[i]/2; -a[i]=a[i]%2; -i++; -a[i]=a[i]+temp; +     } -      for(i=4; i>=0; i--) +     { Aprintf"%d", A[i]); at     } -printf"\ n"); - }
return 0; -}

Code:

"Blue Bridge Cup" basic exercise: 01 Strings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.