import java.util.Scanner;
/**
* Created with IntelliJ IDEA.
* Description:
* User: zhuzhuzhuchao
* Date: 2021-12-25
* Time: 15:16
*/
public class TestDemo {
// 水仙花数 0 - 999999
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();// 999999
findNum(n);
}
public static void findNum(int n) {
for (int i = 1; i <= n; i++) {
int tmp = i;
int count = 0;// 数字位数
while (tmp != 0) {
count++;
tmp /= 10;
}
// count里面知道位数 tmp = 0
tmp = i;
int sum = 0;
while (tmp != 0) {
sum += Math.pow(tmp%10,count);
tmp /= 10;
}
if (sum == i) {
System.out.println(i);
}
}
}
// 写一个函数返回二进制中1的个数(法一)
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
System.out.println(numOfOne(n));
}
public static int numOfOne(int n) {
int count = 0;
while (n != 0) {
if ((n & 1) == 1) {
count++;
}
n = n >>> 1;
}
return count;
}
// 法二
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
System.out.println(numOfOne(n));
}
public static int numOfOne(int n) {
int count = 0;
while (n != 0) {
count++;
n = n & (n-1);
}
return count;
}
// 获取一个二进制数中所有偶数位和奇数位并输出
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
printOne(n);
}
public static void printOne(int n) {
System.out.print("odd :");
for (int i = 30; i >= 0; i-=2) {
System.out.print((n>>i)&1);
}
System.out.println();
System.out.print("even:");
for (int i = 31; i >= 1; i-=2) {
System.out.print((n>>i)&1);
}
}
// 打印每一位
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
print(n);
}
public static void print(int n) {
while (n != 0) {
System.out.print(n%10+" ");
n /= 10;
}
}
// 打印X图形
// 牛客: public class Main
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// while (scanner.hasNextInt()) {} 牛客
int n = scanner.nextInt();
star(n);
}
public static void star(int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) {
System.out.print("*");
} else if (i+j == n-1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
// 找出出现一次的数字
// 1^2^3^2^1 = 0
public static void main(String[] args) {
int[] array = {1,2,3,2,1};
int sum = array[0];
for (int i = 1; i < array.length; i++) {
sum = sum ^ array[i];
}
System.out.println(sum);
}
// 奇数位于偶数之前
// left从前往后走,遇到偶数停下来
// right从后往前走,遇到奇数停下来
// 都停就交换
// 直到相遇
public static void main(String[] args) {
int[] array = {1,2,3,4,5};
int left = 0;
int right = array.length - 1;
while (left < right) {
while (left < right && array[left] % 2 != 0) {
left++;
}
while (left < right && array[right] % 2 == 0) {
right--;
}
int tmp = array[left];
array[left] = array[right];
array[right] = tmp;
}
for (int i = 0; i < array.length; i++) {
System.out.print(array[i]+" ");
}
}
// 求两个数最大值
public static void main(String[] args) {
System.out.println(max3(1,2,3));
}
public static int max2(int a, int b) {
return a > b ? a : b;
}
public static int max3(int a, int b, int c) {
return max2(max2(a,b),c);
}
// 递归
// 方法 自己调用方法的过程
// 前提:1.有一个趋近于终止的条件 2.自己调用自己
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
System.out.println(fac(n));
}
public static int fac(int n) {
if (n == 1) {
return 1;
}
int tmp = n * fac(n-1);
return tmp;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
System.out.println(sum(n));
}
public static int sum(int n) {
if(n == 1) {
return 1;
}
return n + sum(n-1);
}
// 分别打印每一位
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
bit(n);
}
public static void bit(int n) {
if (n < 10) {
System.out.print(n+" ");
} else {
bit(n/10);
System.out.print(n%10+" ");
}
}
// 返回每一位数字之和
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
System.out.println(sum(n));
}
public static int sum(int n) {
if (n < 10) {
return n;
} else {
return n%10 + sum(n/10);
}
}
// fib数列
public static void main(String[] args) {
}
// 迭代实现,循环实现
public static int fib(int n) {
if (n == 1 || n == 2) {
return 1;
}
int f1 = 1;
int f2 = 1;
int f3 = 0;
for (int i = 3; i <= n; i++) {
f3 = f1 + f2;
f1 = f2;
f2 = f3;
}
return f3;
}
// 青蛙跳台阶
// 可以跳1或2,有多少种跳法
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
System.out.println(frogJump(n));
}
// 迭代实现,循环实现
public static int frogJump(int n) {
if (n == 1 || n == 2) {
return n;
}
int f1 = 1;
int f2 = 2;
int f3 = 0;
for (int i = 3; i <= n; i++) {
f3 = f1 + f2;
f1 = f2;
f2 = f3;
}
return f3;
}
}