2 条题解
-
0
#200 水仙花数 题解
这一题很简单,由于水仙花数只有四个: 153、370、371、407
(不要和一位独身数、四叶玫瑰数、五角星数等搞混)
所以只需要判断是否是这四个数就好了(●'◡'●)
#include <iostream> using namespace std; int main(){while (1) { int n;cin >> n; if (n == 0)break; if (n == 153) cout << "Yes\n"; else if (n == 370) cout << "Yes\n"; else if (n == 371) cout << "Yes\n"; else if (n == 407) cout << "Yes\n"; else cout << "No\n"; } }
-
0
C :
#include <stdio.h> int main(){ int n, a, b, c, f; while(scanf("%d", &n) && n != 0){ a = n%10; b = n/10%10; c = n/100; if(a*a*a + b*b*b + c*c*c == n) puts("Yes"); else puts("No"); } return 0; }
C++ :
#include <iostream> using namespace std; int main() { int n,a,b,c; while(cin>>n&&n){ a=n%10; b=n/10%10; c=n/100%10; if(n!=0) if(a*a*a+b*b*b+c*c*c==n){ cout<<"Yes"<<endl; }else{ cout<<"No"<<endl; } else break; } return 0; }
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()) { int n=sc.nextInt(); if(n==0) break; String str=Integer.toString(n); int a=(int)Math.pow((str.charAt(0)-'0'),3); int b=(int)Math.pow((str.charAt(1)-'0'),3); int c=(int)Math.pow((str.charAt(2)-'0'),3); if(a+b+c==n) System.out.println("Yes"); else System.out.println("No"); } } }
- 1
信息
- ID
- 200
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 9
- 标签
- 递交数
- 12
- 已通过
- 4
- 上传者