码迷,mamicode.com
首页 > 其他好文 > 详细

南阳理工OJ之水仙花数

时间:2016-08-21 06:17:01      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

-------------------------------------------

AC代码:

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4 
 5     public static void main(String[] args) {
 6         
 7         Scanner sc=new Scanner(System.in);
 8         
 9         while(true){
10             int n=sc.nextInt();
11             if(n==0) return;
12             System.out.println(solve(n)?"Yes":"No");
13         }
14         
15     }
16     
17     public static boolean solve(int n){
18         int m=n,s=0;
19         while(m>0){
20             int t=m%10;
21             s+=t*t*t;
22             m/=10;
23         }
24         return s==n;
25     }
26     
27 }

 

题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=39

 

南阳理工OJ之水仙花数

标签:

原文地址:http://www.cnblogs.com/cc11001100/p/5791725.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!