Baiti 2973 Skew data solution report

Source: Internet
Author: User

Link: http://poj.grids.cn/practice/2973/

Question:

Total time limit:
1000 ms
Memory limit:
65536kB
Description
In the skew binary representation, the k-bit value xk indicates xk * (2 k + 1-1 ). The possible numbers on each bit are 0 or 1, and the last non-zero bit can be 2, for example, 10120 (skew) = 1 * (25-1) + 0 * (24-1) + 1 * (23-1) + 2 * (22-1) + 0 * (21-1) = 31 + 0 + 7 + 6 + 0 = 44. the top 10 skew numbers are 0, 1, 2, 10, 11, 12, 20, 100, 101, and 102.
Input
The input contains one or more rows. Each row contains an integer n. If n = 0, the input ends. Otherwise, n is a skew.
Output
For each input, it is output in decimal format. After being converted to decimal, n cannot exceed 231-1 = 2147483647
Sample Input
1012020000000000000000000000000000010100000000000000000000000000000011100111110000011100001011011020000
Sample output
44214748364632147483647471041110737

Code:

 #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring>     MAX =                        (scanf(,chs) != EOF && strcmp(chs,          sum =          step =          ( i = strlen(chs)-; i >= ; i--              sum += (chs[i] - ) * (step -              step *=                    cout<<sum<<        }

Ideas:

1. Use int to save the result.

2. You must use a string to read data.

3. Use step for Optimization

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.