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();
}
分类: 计算机语言
[蓝桥杯] 查找整数(使用散列映射)
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;
}
[C++] 可重载运算符列表
[C] stdint.h
内含用typedef表示的各种类型。类型格式如下:
[u]int_[least/fast](8/16/32/64)_t
其中[]中的可填可不填,()中的内容必填。
举个例子:uint_least32_t表示无符号、长度至少32位的整型。
如果只想用可以存储最大数值的类型,请使用(int和max之间没有下划线):
[u]intmax_t
此外,该头文件还包含用宏表示的,上述类型可以存储的最大(小)值。只需要把对应类型全部变为大写,再根据需要把最后的T变为MIN/MAX即可。比如uint_least32_t能储存的最大值为UINT_LEAST32_MAX。
该头文件还有用于转换数字类型的宏:
[U]INT(8/16/32/64/MAX)_C(x)
其中x表示要转换的值(不要跟表示类型的符号)。
比如UINT32_C(45)可能会将45转换成45U。