-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
def is_lucky(num_str): | ||
result, val = True, 0 | ||
for i in range(0, len(num_str)): | ||
val = val * 10 + int(num_str[i]) | ||
result &= val % (i + 1) == 0 | ||
return result | ||
|
||
|
||
input() | ||
num_str_arr = input().split() | ||
for num_str in num_str_arr: | ||
print("Yes" if is_lucky(num_str) else "No") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
input() | ||
arr = map(int, input().split()) | ||
# filter out even numbers | ||
arr = list(filter(lambda v: v % 2 == 1, arr)) | ||
result = arr[0] | ||
# xor remove odd number pair | ||
for i in range(1, len(arr)): | ||
result ^= arr[i] | ||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from decimal import * | ||
|
||
|
||
def round_number(method, number, precision): | ||
context = getcontext() | ||
context.prec = 300 # 精度位数一定要大 | ||
if method == "1": | ||
context.rounding = ROUND_HALF_UP | ||
elif method == "2": | ||
context.rounding = ROUND_DOWN | ||
elif method == "3": | ||
context.rounding = ROUND_HALF_EVEN | ||
|
||
d = Decimal(number).quantize(Decimal("0." + "0" * precision)) | ||
if d == 0: | ||
d = abs(d) | ||
ans = str(d) | ||
if ans[0] == "+": | ||
ans = ans[1:] | ||
return ans | ||
|
||
|
||
n, d = map(int, input().split()) | ||
for i in range(n): | ||
op, num = input().split() | ||
print(round_number(op, num, d)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
fib = [0, 1] | ||
|
||
count = 0 | ||
while fib[-1] <= 10**8: | ||
new = fib[-1] + fib[-2] | ||
fib.append(new) | ||
|
||
v = int(input()) | ||
ans, diff = -1, 10**8 | ||
for i in range(len(fib)): | ||
if fib[i] >= v: | ||
if abs(fib[i] - v) < diff: | ||
ans = fib[i] | ||
break | ||
else: | ||
ans = fib[i] | ||
diff = abs(fib[i] - v) | ||
print(ans) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <iostream> | ||
#include <vector> | ||
using namespace std; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
string s, p; | ||
cin >> s >> p; | ||
|
||
pair<int, string> ans{10e5+10, ""}; | ||
// brute force match p in s and find the shortest substring | ||
for (int i = 0; i < s.size(); i++) { | ||
if (s[i] != p[0]) continue; | ||
int l = i, r = l+1; | ||
int k = 1; | ||
for (; r < s.size() && k != p.size(); r++) { | ||
if (s[r] == p[k]) k++; | ||
if (k == p.size()) break; | ||
} | ||
|
||
int len = r-l+1; | ||
if (k == p.size() && len < ans.first) { | ||
ans.first = len; | ||
ans.second = s.substr(l, len); | ||
} | ||
} | ||
|
||
cout << ans.second << endl; | ||
return 0; | ||
} |