Introduction to Programming--c Language 3rd week programming Exercise 2 numeric eigenvalues (5 points)

Source: Internet
Author: User

2

Numeric eigenvalues (5 points)

Topic content:

It is a common coding algorithm to find the eigenvalues of numbers, and the odd-even feature is a simple characteristic value. For an integer, each digit is numbered from bit to digit, number 1th, 10 digit is 2nd, and so on. This integer number on the nth bit is recorded as x, if the parity of X and N is the same, write down a 1, otherwise write down a 0. 0 and 1 of the parity of the corresponding bit are recorded in the order of integers, and a binary number is formed. For example, for 342315, this binary number is 001101.

The calculation here can be expressed in the following table:

number

3

4

2

3

1

5

digits

6

5

4

3

2

1

digital parity

odd

even

odd

odd

odd

digital parity

even

odd

odd

odd

parity consistent

0

0

1

1

0

1

Bits value

32

16

8

4

2

1

Your program reads a nonnegative integer, the range of integers is [0,1000000], and then calculates the binary number that represents the parity by the above algorithm, outputting its corresponding decimal value.

Tip: The integer is decomposed from right to left, the digits are added 1 at a time, and the binary value is multiplied by 2.

Input format:

A nonnegative integer in which the range of integers is [0,1000000].

Output format:

An integer that represents the result of the calculation.

Input Sample:

342315

Sample output:

13

Time limit: 500ms memory limit: 32000kb

  main.c//  C yuyan////  Created by Anzhongyin on 2016/11/29.//  Copyright 2016 anzhongyin. All rights reserved.//#include <stdio.h>int main (int argc, const char * argv[]) {    //Insert code    here ... int Inter;    int n=1;    int sum=0;    int m=1;    scanf ("%d", &inter);    while (inter>0)    {        m=1;       if ((inter%10%2==0&&n%2==0) | | | (inter%10%2!=0&&n%2!=0))       {for           (int i=1;i<n;i++)           {               m=m*2;           }            sum=sum+m;       }        INTER=INTER/10;        n++;    }        printf ("%d\n", sum);    return 0;}

  

Use case test Results

Run time

Memory consumption

Tips

Score

Use Case 1 by

1ms

256kb

1

Use Case 2 by

13ms

256kb

1

Use Case 3 by

1ms

256kb

1

Use Case 4 by

1ms

128kb

1

Use Case 5 by

1ms

148kb

1

Submit an Answer

Score/Score:5.00/5.00 min

Introduction to Programming--c Language 3rd week programming Exercise 2 numeric eigenvalues (5 points)

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.