Scanner in = new Scanner(System.in);
int line = in.nextInt();
int[] arr = new int[line];
Arrays.fill(arr, 1);
for (int i = 0; i < line; i++) {
for (int j = i - 1; j > 0; j--) {
arr[j] += arr[j - 1];
}
for (int j = 0; j <= i; j++) {
System.out.printf("%d ", arr[j]);
}
System.out.println();
}
月度归档: 2021 年 1 月
[蓝桥杯] 查找整数(使用散列映射)
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int leng = in.nextInt();
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < leng; i++) {
map.putIfAbsent(in.nextInt(), i + 1);
}
System.out.println(map.getOrDefault(in.nextInt(), -1));
}
[蓝桥杯] 回文数
for(int i = 10; i< 100; i++) {
System.out.printf("%d%02d%n", i, (i % 10 * 10 + i / 10));
}
[蓝桥杯] 字母图形
static Scanner in = new Scanner(System.in);
static String pattern = "ZYXWVUTSRQPONMLKJIHGFEDCBABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static void main(String[] args) {
int line = in.nextInt(), col = in.nextInt();
for(int i=0;i<line;i++) {
System.out.println(pattern.substring(25 - i, 25 - i + col));
}
}
[蓝桥杯] Fibonacci 数列
static int f(int num) {
int fn1 = 1, fn2 = 1;
while(num-- > 2) {
// 原题要求如此,不需要的话把模删掉,再把返回类型换成更大的
int fn = (fn1 + fn2) % 10007;
fn2 = fn1;
fn1 = fn;
}
return fn1;
}