diff --git a/com/study/demo/Demo.java b/com/study/demo/Demo.java new file mode 100644 index 0000000..cd317cd --- /dev/null +++ b/com/study/demo/Demo.java @@ -0,0 +1,7 @@ +package com.study.demo; + +public class Demo { + public static void main(String [] args) { + System.out.println("HelloWorld!"); + } +} diff --git a/com/study/demo/test1_1.java b/com/study/demo/test1_1.java new file mode 100644 index 0000000..5f0e51d --- /dev/null +++ b/com/study/demo/test1_1.java @@ -0,0 +1,13 @@ +package com.study.demo; +import java.util.Scanner; +// I am 212306206 +public class test1_type { + public static void main(String[] args) { + Scanner scanner = new Scanner (System.in); + int a = scanner.nextInt(); + int b = scanner.nextInt(); + int sum = a + b; + System.out.println(a + " + " + b + " = " + sum); + scanner.close(); + } +} diff --git a/com/study/demo/test1_2.java b/com/study/demo/test1_2.java new file mode 100644 index 0000000..31d5ee0 --- /dev/null +++ b/com/study/demo/test1_2.java @@ -0,0 +1,16 @@ +package com.study.demo; + +public class test2_for { + public static void main(String[] args) { + int[] numbers = new int[5]; + for (int i = 0; i < numbers.length; i++) { + numbers[i] = i * 10; + } + + System.out.print("数组内容: "); + for (int i = 0; i < numbers.length; i++) { + System.out.print(numbers[i] + " "); + } + } +} + diff --git a/com/study/demo/test1_3.java b/com/study/demo/test1_3.java new file mode 100644 index 0000000..05189ee --- /dev/null +++ b/com/study/demo/test1_3.java @@ -0,0 +1,19 @@ +package com.study.demo; + +public class test3_1_99 { + public static void main(String[] args) { + int[] numbers = new int[99]; + + for (int i = 0; i < numbers.length; i++) { + numbers[i] = i + 1; + } + + int sum = 0; + for (int i = 0; i < numbers.length; i++) { + sum += numbers[i]; + } + + System.out.println("1+2+...+99 的和 = " + sum); + } +} + diff --git a/com/study/demo/test2_1.java b/com/study/demo/test2_1.java new file mode 100644 index 0000000..bf44c29 --- /dev/null +++ b/com/study/demo/test2_1.java @@ -0,0 +1,14 @@ +package com.study.demo; +import java.util.Scanner; + +public class test4 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + double r1 = sc.nextDouble(); + double r2 = sc.nextDouble(); + sc.close(); + + double R = 1 / (1 / r1 + 1 / r2); + System.out.printf("%.2f\n", R); + } +} diff --git a/com/study/demo/test2_2.java b/com/study/demo/test2_2.java new file mode 100644 index 0000000..f3b570f --- /dev/null +++ b/com/study/demo/test2_2.java @@ -0,0 +1,14 @@ +package com.study.demo; +import java.util.Scanner; + +public class test5 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int a = scanner.nextInt(); + int b = scanner.nextInt(); + int c = scanner.nextInt(); + double pi = 3.1415926535; + double area = a * b * c + a * c + (pi * c * c) / 4; + System.out.printf("%.3f\n", area / 10000); + } +} \ No newline at end of file diff --git a/com/study/demo/test2_3.java b/com/study/demo/test2_3.java new file mode 100644 index 0000000..f1ae9e3 --- /dev/null +++ b/com/study/demo/test2_3.java @@ -0,0 +1,12 @@ +package com.study.demo; + +import java.util.Scanner; + +public class test6 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int n = scanner.nextInt(); + int result = 1 << n; + System.out.println(result); + } +} \ No newline at end of file diff --git a/com/study/demo/test2_4.java b/com/study/demo/test2_4.java new file mode 100644 index 0000000..0f0ced7 --- /dev/null +++ b/com/study/demo/test2_4.java @@ -0,0 +1,14 @@ +package com.study.demo; + +import java.util.Scanner; + +public class test7 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int x = scanner.nextInt(); + int y = scanner.nextInt(); + int startYear = 2016, startMonth = 8; + int totalMonths = (x - startYear) * 12 + y - startMonth + 1; + System.out.println(totalMonths); + } +} \ No newline at end of file diff --git a/com/study/demo/test2_5.java b/com/study/demo/test2_5.java new file mode 100644 index 0000000..87d354a --- /dev/null +++ b/com/study/demo/test2_5.java @@ -0,0 +1,19 @@ +package com.study.demo; + +import java.util.Scanner; + +public class test8 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int x = scanner.nextInt(); + int k = scanner.nextInt(); + int a = x / 1000 % k; + int b = x / 100 % 10 % k; + int c = x / 10 % 10 % k; + int d = x % 10 % k; + System.out.print(a); + System.out.print(b); + System.out.print(c); + System.out.println(d); + } +} diff --git a/com/study/demo/test3_1.class b/com/study/demo/test3_1.class new file mode 100644 index 0000000..8a09b03 Binary files /dev/null and b/com/study/demo/test3_1.class differ diff --git a/com/study/demo/test3_1.java b/com/study/demo/test3_1.java new file mode 100644 index 0000000..ef5f27b --- /dev/null +++ b/com/study/demo/test3_1.java @@ -0,0 +1,22 @@ +package com.study.demo; + +import java.util.Scanner; + +public class test3_1 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int n = scanner.nextInt(); + int[] arr = new int[n]; + for (int i = 0; i < n; i++) { + arr[i] = scanner.nextInt(); + } + for (int i = 0; i < n / 2; i++) { + int temp = arr[i]; + arr[i] = arr[n - 1 - i]; + arr[n - 1 - i] = temp; + } + for (int i = 0; i < n; i++) { + System.out.print(arr[i] + (i == n - 1 ? "" : " ")); + } + } +} diff --git a/com/study/demo/test3_2.class b/com/study/demo/test3_2.class new file mode 100644 index 0000000..5ba259a Binary files /dev/null and b/com/study/demo/test3_2.class differ diff --git a/com/study/demo/test3_2.java b/com/study/demo/test3_2.java new file mode 100644 index 0000000..6c23487 --- /dev/null +++ b/com/study/demo/test3_2.java @@ -0,0 +1,23 @@ +package com.study.demo; + +import java.util.Scanner; + +public class test3_2 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int n = scanner.nextInt(); + int[] a = new int[n]; + int[] b = new int[n]; + for (int i = 0; i < n; i++) { + a[i] = scanner.nextInt(); + } + for (int i = 0; i < n; i++) { + b[i] = scanner.nextInt(); + } + int sum = 0; + for (int i = 0; i < n; i++) { + sum += a[i] * b[i]; + } + System.out.println(sum); + } +} diff --git a/com/study/demo/test3_3.class b/com/study/demo/test3_3.class new file mode 100644 index 0000000..0f74550 Binary files /dev/null and b/com/study/demo/test3_3.class differ diff --git a/com/study/demo/test3_3.java b/com/study/demo/test3_3.java new file mode 100644 index 0000000..1b1d23b --- /dev/null +++ b/com/study/demo/test3_3.java @@ -0,0 +1,25 @@ +package com.study.demo; + +import java.util.Scanner; + +public class test3_3 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int n = scanner.nextInt(); + int[] arr = new int[n]; + for (int i = 0; i < n; i++) { + arr[i] = scanner.nextInt(); + } + int maxLen = 1, currentLen = 1; + for (int i = 1; i < n; i++) { + if (arr[i] == arr[i - 1]) { + currentLen++; + } else { + maxLen = Math.max(maxLen, currentLen); + currentLen = 1; + } + } + maxLen = Math.max(maxLen, currentLen); + System.out.println(maxLen); + } +} diff --git a/com/study/demo/test3_4.class b/com/study/demo/test3_4.class new file mode 100644 index 0000000..04b1e71 Binary files /dev/null and b/com/study/demo/test3_4.class differ diff --git a/com/study/demo/test3_4.java b/com/study/demo/test3_4.java new file mode 100644 index 0000000..63d2a91 --- /dev/null +++ b/com/study/demo/test3_4.java @@ -0,0 +1,23 @@ +package com.study.demo; + +import java.util.Scanner; + +public class test3_4 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int n = scanner.nextInt(); + int m = scanner.nextInt(); + int[][] image = new int[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + image[i][j] = scanner.nextInt(); + } + } + for (int j = 0; j < m; j++) { + for (int i = n - 1; i >= 0; i--) { + System.out.print(image[i][j] + (i == 0 ? "" : " ")); + } + System.out.println(); + } + } +} diff --git a/com/study/demo/test3_5.class b/com/study/demo/test3_5.class new file mode 100644 index 0000000..596c796 Binary files /dev/null and b/com/study/demo/test3_5.class differ diff --git a/com/study/demo/test3_5.java b/com/study/demo/test3_5.java new file mode 100644 index 0000000..574959b --- /dev/null +++ b/com/study/demo/test3_5.java @@ -0,0 +1,34 @@ +package com.study.demo; + +import java.util.Scanner; + +public class test3_5 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int n = scanner.nextInt(); + int[] t = new int[n - 1]; + int[] s = new int[n]; + for (int i = 0; i < n - 1; i++) { + t[i] = scanner.nextInt(); + } + for (int i = 0; i < n; i++) { + s[i] = scanner.nextInt(); + } + int x = scanner.nextInt(); + int y = scanner.nextInt(); + + int total = 0; + if (x < y) { + for (int i = x - 1; i < y - 1; i++) { + total += s[i] + t[i]; + } + total += s[y - 1]; + } else { + for (int i = x - 1; i >= y; i--) { + total += s[i] + (i > 0 ? t[i - 1] : 0); + } + total += s[y - 1]; + } + System.out.println(total); + } +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3d8d012 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1759070547, + "narHash": "sha256-JVZl8NaVRYb0+381nl7LvPE+A774/dRpif01FKLrYFQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "647e5c14cbd5067f44ac86b74f014962df460840", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..3ca1e3b --- /dev/null +++ b/flake.nix @@ -0,0 +1,21 @@ +{ + description = "A Nix-flake-based development environment"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + outputs = { self, nixpkgs }: + let + supportedSystems = [ "x86_64-linux" "aarch64-linux" ]; + forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f { + pkgs = import nixpkgs { inherit self system; }; + }); + in + { + devShells = forEachSupportedSystem ({ pkgs }: { + default = pkgs.mkShell { + packages = with pkgs; [ + jdk8 + ]; + }; + }); + }; +} +