(Java implementation) Hangzhou electric OJ 2097 Sky number

Source: Internet
Author: User

is simply to find out the sum of the various systems, compare whether the equality is good

Sky number

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 20822 Accepted Submission (s): 11865


Problem Descriptionsky from childhood like strange things, and is born particularly sensitive to the number, an accidental opportunity, he found an interesting four-digit 2992, this number, its decimal number, its four-digit sum of 2+9+9+2=22, its hexadecimal number BB0 , its four-digit sum is also 22, at the same time its 12 binary number means 1894, its four-digit sum is 22, ah ha, really clever ah. Sky is very fond of this four-digit number, because of his discovery, so here we name it as Sky number. But to judge such a number is still a bit of trouble ah, so now please help to judge any decimal four digits, is not the sky number bar.

The input input contains some four-bit positive integers, and if 0, the entry ends.

Output "#n is a sky number if n is sky.", otherwise the output "#n is not a sky numbers." Each result occupies one row. Note: #n表示所读入的n值.

Sample Input299212340

Sample Output2992 is a Sky number.1234 are not a sky number.
Import Java.util.scanner;public class Main {public static void main (string[] args) {Scanner scan = new Scanner (system.in);  while (Scan.hasnext ()) {  int n=scan.nextint ();  if (n==0) break;  int s1=f (n,10), S2=f (n,12), s3=f (n,16);      if (S1==S2&&S2==S3)      System.out.println (n + "is a Sky number.");      else       System.out.println (n + "is not a Sky number.");}  } public static int f (int n,int i) {int s=0;while (n!=0) {s+=n%i;n/=i;} return s;}}

  

(Java implementation) Hangzhou electric OJ 2097 Sky number

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.