51NOD 1413 powerful binary (thinking)

Source: Internet
Author: User

Portal

A decimal integer is called the Power binary, when his decimal representation is made up of only 0 or 1. For example, 0,1,101,110011 are powerful binaries and 2,12,900 not.
When given an n, calculate the minimum number of powerful binary additions to get N.

Input
A single set of test data.
The first line gives an integer n (1<=n<=1,000,000)
Output
One row for the output answer.
Input example
9
Output example
9

Problem Solving Ideas:
This topic, in fact, the problem is to find the largest number of all digits, this is difficult to think of. As an example:
9998 can be obtained by 8 of 1111 and one 1110:
5656 can be obtained by 5 of 1111 and one 101
5678 can be obtained by 5 1111 and one 111 and one 11 and one 1
So it is to ask for a maximum value of 10 for each bit.

My Code:

 #include <iostream>   #include <cstdio>  using  Span class= "Hljs-keyword" >namespace  STD ;    int  Main () {int  N; scanf     ( "%d" , &n);    int  ans = 0 ; while         (n) {int  m = N%10 ; if         (Ans < m) ans = m;    n/= 10 ;    } cout  <<ans<<endl; return  0 ;}  

51NOD 1413 Powerful binary (thinking)

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.