Huawei on-machine test question (Narcissus number upgrade version-java)

Source: Internet
Author: User

PS: This question is out of 100, did not do, everybody helps to see where the problem is

/*
* Title: Narcissus number upgrade version
* Description: Narcissus number refers to an n-digit number (n≥3), and its number on each bit of the sum of n is equal to its own. (Example: 1^3 + 5^3+ 3^3 = 153)
Give you A and B, how many daffodils are there in the [a b] interval

Topic Category: Loops, lookups, enumerations, bitwise operations
Difficulty: Intermediate
Score: 100
Run time limit: Unlimited
Memory Limit: Unlimited
Stage: Application for examination
Input: Two positive integers, separated by a space, to ensure that the number is less than or equal to 1000000.

Output: A number representing the number of daffodils in the [a, b] interval

Sample input: 100 1000

Sample output: 4

Answer hint: The number of daffodils in 100~1000:153,370,371,407
*/

1 ImportJava.util.Scanner;2 3  Public classMain {4 5      Public Static voidMain (string[] args) {6         7         intA = 0;8         intb = 0;9         intCount = 0;Ten          OneScanner s =NewScanner (system.in); AString str =s.nextline (); -string[] Strarray = Str.split (""); -A = Integer.parseint (strarray[0]); theb = Integer.parseint (strarray[1]); - s.close (); -         if(A < | | a > 1000000) | | (B < | | b > 1000000)) -         { +             Throw Newruntimeexception (); -         } +          ACount =Getnum (A, b); at          - System.out.println (count); -     } -  -      Public Static intGetnum (intAintb) { -          in         intresult = 0; -          to          for(inti = A; I <= b; i++) +         { -             intm =i; the             intTMP = 0; *             intValue = 0; $             Panax Notoginseng              while(0! =m) -             { the                  +TMP = M%10; AValue + = Math.pow (tmp, 3); theM/= 10; +             } -              $             if(Value = =i) $             { -result++; -             } the         } -         returnresult;Wuyi     } the      -}

Huawei on-machine test question (Narcissus number upgrade version-java)

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.