Basic exercise of "Blue Bridge Cup": 01 string, Blue Bridge string

Source: Internet
Author: User

Basic exercise of "Blue Bridge Cup": 01 string, Blue Bridge string

Problem description

For a 01 string with a length of 5 digits, each digit may be 0 or 1, a total of 32 possibilities. The first few of them are:

00000

00001

00010

00011

00100

Output these 32 01 strings in ascending order.

The input format is not entered. The output format outputs 32 rows. Each row has a 01 string of 5 in ascending order. Sample output 00000
00001
00010
00011
<The following part is omitted> tips: This question reminds me of the idea of using an integer array to store large numbers. The idea is to calculate the first element each time, and then adjust it. If each element in the array does not overflow, use while.
1 # include <stdio. h> 2 int main (void) 3 {4 int a [5] = {0}; 5 int temp; 6 int times; 7 int I; 8 printf ("00000 \ n"); 9 for (times = 1; times <= 31; times ++) 10 {11 I = 0; 12 a [I] + = 1; 13 while (a [I]> = 2) 14 {15 temp = a [I]/2; 16 a [I] = a [I] % 2; 17 I ++; 18 a [I] = a [I] + temp; 19} 20 for (I = 4; i> = 0; I --) 21 {22 printf ("% d", a [I]); 23} 24 printf ("\ n"); 25}
Return 0; 26}

 

Code:

Related Article

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.