Skip to content

Commit 2c13aaa

Browse files
authored
add 14010930 files
1 parent c7aef00 commit 2c13aaa

8 files changed

Lines changed: 244 additions & 0 deletions

File tree

14010930/Benchmark1.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Benchmark1 {
2+
public static void main(String[] args) {
3+
for (int i = 1; i < 1000 * 1000; i++) {
4+
double r = Math.sqrt(i);
5+
}
6+
}
7+
}

14010930/Benchmark2.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Benchmark2 {
2+
public static void main(String[] args) {
3+
for (int i = 1; i < 1000 * 1000; i++) {
4+
long r = (long) i * i;
5+
}
6+
}
7+
}

14010930/Main.java

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import java.util.Scanner;
2+
3+
class Main {
4+
public static void main(String[] args) {
5+
Scanner input = new Scanner(System.in);
6+
System.out.println("hello");
7+
System.out.println("1");
8+
// int [-2^31, 2^31)
9+
// long [-2^63, 2^63)
10+
// double 64-bit
11+
// float 32-bit
12+
// boolean true false
13+
// String "asdasd 123dasd"
14+
15+
String parsa;
16+
parsa = " ";
17+
String parsaa = " ";
18+
19+
parsa = "lala";
20+
int r = 2;
21+
long a = 2;
22+
double t = 2.0;
23+
boolean c;
24+
c = true;
25+
c = false;
26+
double da = 0.1;
27+
double db = 0.2;
28+
double dsum = da + db;
29+
System.out.println(dsum); // 0.3?
30+
31+
// + - * / %
32+
// += -= *= /= %=
33+
a = a + 1;
34+
a += 1;
35+
// 7 % 2
36+
// < > <= >= == !=
37+
// 1 == 2
38+
// 1 != 2
39+
40+
// ++ --
41+
int aa = 1;
42+
aa++;
43+
aa = aa + 1;
44+
aa += 1;
45+
aa--;
46+
aa = aa - 1;
47+
aa -= 1;
48+
49+
int first = input.nextInt();
50+
int second = input.nextInt();
51+
int sum = first + second;
52+
System.out.println(sum);
53+
int n = input.nextInt();
54+
if (n % 3 == 0) {
55+
System.out.println("salam");
56+
}
57+
else if (n % 3 == 1) {
58+
System.out.println("hello");
59+
}
60+
else {
61+
System.out.println("bye");
62+
}
63+
int m = input.nextInt();
64+
int sum1 = 0;
65+
int j = 1;
66+
while (j <= m) {
67+
sum1 += j;
68+
j++;
69+
}
70+
System.out.println(sum1);
71+
72+
int k = 1;
73+
while (k <= n) {
74+
// code
75+
k++;
76+
}
77+
78+
// for (int i = 1; i <= n; i++) {
79+
// code
80+
// }
81+
82+
// for (int i = 100; i >= 0; i /= 2) {
83+
// }
84+
85+
Math.max(2, 3);
86+
Math.min(2, 3);
87+
String s = "hello";
88+
char ch = 'a';
89+
// s.charAt(0) == 'h';
90+
s.length();
91+
// s.substring(i, j); // [i, j)
92+
// s.substring(1, 2) == "e"; // wrong, correct form:
93+
// s.substring(1, 2).equals("e");
94+
// s.charAt(1) == 'e';
95+
// .equals();
96+
String s1 = input.next();
97+
String s2 = input.next();
98+
// Math.pow(a, b); // a^b
99+
boolean boo = false;
100+
// !t
101+
// if (!s.equals(t)) { // !=
102+
103+
// }
104+
// int a = 1;
105+
// int b = 2;
106+
// if (a != b)
107+
// if (!(a == b))
108+
String st = "hello world";
109+
if (st.substring(1, 4).equals("ell")) {
110+
System.out.println("YES");
111+
}
112+
else {
113+
System.out.println("NO");
114+
}
115+
// Math.sqrt(n);
116+
117+
double rootOfFour = Math.sqrt(4); // 2.0
118+
119+
// i = 1 ... sqrt(n)
120+
for (int i = 1; i <= Math.sqrt(n); i++) {
121+
System.out.println(i);
122+
}
123+
// OR
124+
for (int i = 1; i * i <= n; i++) {
125+
System.out.println(i);
126+
}
127+
// Second approach is better, because it doesn't have imprecision,
128+
// and it's faster because Math.sqrt is expensive in terms of time.
129+
for (int i = 1; i <= 10; i++) {
130+
if (i == 5) {
131+
continue;
132+
}
133+
System.out.println(i);
134+
}
135+
136+
// || && !
137+
// if (1 == 2 || 2 == 2) {
138+
// condition is true;
139+
// }
140+
// if (1 == 2 && 2 == 2) {
141+
// condition is false;
142+
// }
143+
int[] array = new int[5];
144+
for (int i = 0; i < 5; i++) {
145+
array[i] = (i + 1) * (i + 1);
146+
}
147+
// OR
148+
for (int i = 1; i <= 5; i++) {
149+
array[i - 1] = i * i;
150+
}
151+
for (int i = 0; i < 5; i++) {
152+
System.out.print(array[i] + " ");
153+
}
154+
}
155+
}

14010930/Prime.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.Scanner;
2+
3+
class Prime {
4+
public static void main(String[] args) {
5+
Scanner stdin = new Scanner(System.in);
6+
int n = stdin.nextInt();
7+
int i = 2;
8+
while (i * i <= n) {
9+
if (n % i == 0) {
10+
break;
11+
}
12+
i++;
13+
}
14+
if (n == 1) {
15+
System.out.println("no");
16+
}
17+
else if (n == 2) {
18+
System.out.println("yes");
19+
}
20+
else if (n % i == 0) {
21+
System.out.println("no");
22+
}
23+
else {
24+
System.out.println("yes");
25+
}
26+
}
27+
}

14010930/Quera282.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.util.Scanner;
2+
3+
class Quera282 {
4+
public static void main(String[] args) {
5+
Scanner stdin = new Scanner(System.in);
6+
int n = stdin.nextInt();
7+
int sumOfDivisors = 0;
8+
for (int i = 1; i < n; i++) {
9+
if (n % i == 0) {
10+
sumOfDivisors += i;
11+
}
12+
}
13+
if (sumOfDivisors == n) {
14+
System.out.println("YES");
15+
}
16+
else {
17+
System.out.println("NO");
18+
}
19+
}
20+
}

14010930/Quera589.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import java.util.Scanner;
2+
3+
class Quera589 {
4+
public static void main(String[] args) {
5+
Scanner stdin = new Scanner(System.in);
6+
int n = stdin.nextInt();
7+
int answer = 1;
8+
int i = 1;
9+
while (i <= n) {
10+
answer = answer * i; // answer *= i;
11+
i++;
12+
}
13+
System.out.println(answer);
14+
}
15+
}

14010930/benchmark_results.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
java Benchmark1 0.08s user 0.10s system 25% cpu 0.712 total
2+
java Benchmark2 0.08s user 0.04s system 62% cpu 0.192 total

14010930/problems.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
discussed in class:
2+
https://quera.org/problemset/589/
3+
https://quera.org/problemset/282/
4+
https://quera.org/problemset/9774/
5+
6+
not discussed in class:
7+
https://quera.org/problemset/280/
8+
https://quera.org/problemset/588/
9+
https://quera.org/problemset/591/
10+
https://quera.org/problemset/617/
11+

0 commit comments

Comments
 (0)