Skip to content

Commit 3b43892

Browse files
committed
add 1111-1115 and 1168-1169
1 parent fdb7f27 commit 3b43892

File tree

8 files changed

+223
-1
lines changed

8 files changed

+223
-1
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ root = true
44
# all files
55
[*]
66
indent_style = tab
7-
indent_size = 4
7+
indent_size = 2
88
charset = utf-8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def isPrime(n):
2+
if n == 1:
3+
return False
4+
for i in range(2, int(n**0.5)+1):
5+
if n % i == 0:
6+
return False
7+
return True
8+
9+
d = input()
10+
11+
ok = True
12+
for i in range(len(d)):
13+
t = d[i:]
14+
r = isPrime(int(t))
15+
ok &= r
16+
print("{} {}".format(t, "Yes" if r else "No"))
17+
if ok:
18+
print("All Prime!")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <iostream>
2+
#include <unordered_set>
3+
#include <vector>
4+
using namespace std;
5+
int main() {
6+
ios::sync_with_stdio(false);
7+
unordered_set<int> s, out;
8+
int a, b, n, m;
9+
cin >> a >> b;
10+
s.insert(a);
11+
s.insert(b);
12+
cin >> n >> m;
13+
vector<vector<int>> v(n, vector<int>(m));
14+
15+
for (int i = 0; i < n; i++) {
16+
for (int j = 0; j < m; j++) {
17+
cin >> v[i][j];
18+
}
19+
}
20+
21+
// for loop by round
22+
for (int j = 0; j < m; j++) {
23+
for (int i = 0; i < n; i++) {
24+
// if player i is out, skip
25+
if (out.find(i) != out.end()) continue;
26+
27+
int t = v[i][j];
28+
// if t is in s, player i is out
29+
if (s.find(t) != s.end()) {
30+
cout << "Round #" << j + 1 << ": " << i+1 << " is out." << endl;
31+
out.insert(i);
32+
} else {
33+
// if t is not in s, check if t + any element in s is in s
34+
bool isValid = false;
35+
for (auto it = s.begin(); it != s.end(); it++) {
36+
if (s.find(*it + t) != s.end()) {
37+
isValid = true;
38+
break;
39+
}
40+
}
41+
42+
// if t + any element in s is in s, player i is out
43+
// else insert t into s
44+
if (isValid) s.insert(t);
45+
else {
46+
cout << "Round #" << j + 1 << ": " << i+1 << " is out." << endl;
47+
out.insert(i);
48+
}
49+
}
50+
}
51+
}
52+
53+
if (out.size() == (size_t)n) cout << "No winner." << endl;
54+
else {
55+
cout << "Winner(s):";
56+
for (int i = 0; i < n; i++) {
57+
if (out.find(i) == out.end()) {
58+
cout << " " << i+1;
59+
}
60+
}
61+
cout << endl;
62+
}
63+
64+
return 0;
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import datetime
2+
3+
def isPalindromic(s):
4+
return s == s[::-1]
5+
6+
month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
7+
8+
n = int(input())
9+
for i in range(n):
10+
s = input()
11+
md, y = s.split(',')
12+
y = y.strip().zfill(4)
13+
m, d = md.split(' ')
14+
m = str(month.index(m) + 1).zfill(2)
15+
d = d.zfill(2)
16+
date = y + m + d
17+
print('Y' if isPalindromic(date) else 'N', end=' ')
18+
print(date)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
n, t = map(int, input().split())
2+
points = list(map(int, input().split()))
3+
4+
m = max(points)
5+
if m <= t:
6+
print(m)
7+
else:
8+
begin = -1
9+
for i in range(n):
10+
if points[i] > t:
11+
if begin == -1:
12+
begin = i
13+
if points[i] <= t and begin != -1:
14+
print("[{}, {}]".format(begin, i-1))
15+
begin = -1
16+
if begin != -1:
17+
print("[{}, {}]".format(begin, n-1))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
bs="0123456789abcdefghijklmnopqrstuvwxyz"
2+
3+
def add(a, b, base):
4+
a, b = a[::-1], b[::-1]
5+
c = ""
6+
carry = 0
7+
for i in range(max(len(a), len(b))):
8+
if i < len(a):
9+
carry += bs.index(a[i])
10+
if i < len(b):
11+
carry += bs.index(b[i])
12+
c += bs[carry % base]
13+
carry //= base
14+
if carry:
15+
c += bs[carry]
16+
while len(c) > 1 and c[-1] == "0":
17+
c = c[:-1]
18+
return c[::-1]
19+
20+
a, b = input().split()
21+
print(add(a, b, 30))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def isPrime(n):
2+
if n == 1:
3+
return False
4+
for i in range(2, int(n**0.5)+1):
5+
if n % i == 0:
6+
return False
7+
return True
8+
9+
d = input()
10+
11+
ok = True
12+
for i in range(len(d)):
13+
t = d[i:]
14+
r = isPrime(int(t))
15+
ok &= r
16+
print("{} {}".format(t, "Yes" if r else "No"))
17+
if ok:
18+
print("All Prime!")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <iostream>
2+
#include <unordered_set>
3+
#include <vector>
4+
using namespace std;
5+
int main() {
6+
ios::sync_with_stdio(false);
7+
unordered_set<int> s, out;
8+
int a, b, n, m;
9+
cin >> a >> b;
10+
s.insert(a);
11+
s.insert(b);
12+
cin >> n >> m;
13+
vector<vector<int>> v(n, vector<int>(m));
14+
15+
for (int i = 0; i < n; i++) {
16+
for (int j = 0; j < m; j++) {
17+
cin >> v[i][j];
18+
}
19+
}
20+
21+
// for loop by round
22+
for (int j = 0; j < m; j++) {
23+
for (int i = 0; i < n; i++) {
24+
// if player i is out, skip
25+
if (out.find(i) != out.end()) continue;
26+
27+
int t = v[i][j];
28+
// if t is in s, player i is out
29+
if (s.find(t) != s.end()) {
30+
cout << "Round #" << j + 1 << ": " << i+1 << " is out." << endl;
31+
out.insert(i);
32+
} else {
33+
// if t is not in s, check if t + any element in s is in s
34+
bool isValid = false;
35+
for (auto it = s.begin(); it != s.end(); it++) {
36+
if (s.find(*it + t) != s.end()) {
37+
isValid = true;
38+
break;
39+
}
40+
}
41+
42+
// if t + any element in s is in s, player i is out
43+
// else insert t into s
44+
if (isValid) s.insert(t);
45+
else {
46+
cout << "Round #" << j + 1 << ": " << i+1 << " is out." << endl;
47+
out.insert(i);
48+
}
49+
}
50+
}
51+
}
52+
53+
if (out.size() == (size_t)n) cout << "No winner." << endl;
54+
else {
55+
cout << "Winner(s):";
56+
for (int i = 0; i < n; i++) {
57+
if (out.find(i) == out.end()) {
58+
cout << " " << i+1;
59+
}
60+
}
61+
cout << endl;
62+
}
63+
64+
return 0;
65+
}

0 commit comments

Comments
 (0)