AtCoder Beginner Contest 282(python3)
A Generalized ABC
- 题意:输出从’A’开始的升序的前k个英文字母
- 范围:k <= 26
- 写法:
range(n)
表示[0, n - 1]
range(x, y)
表示[x, y - 1]
ord('A')
返回’A’的Unicode编码
chr(Unicode编码)
返回对应的字符
k = int(input())
ans = ''
for i in range(k):
ans += chr(ord('A') + i)
print(ans)
B - Let’s Get a Perfect Score
-
题意 :n个人,m个问题,给出n个人分别的对于这m个问题是否能解决的字符串,用ox分别表示。现在从这n个人中挑出一对人,要求这两个人加起来能解决所有m个问题,问这样的对数
-
范围:
N is an integer between 2 and 30, inclusive.
M is an integer between 1 and 30, inclusive. -
题解:枚举每一对,只要能找到一个位置均为x,说明这对不行
-
写法:
输入方式“n m”n, m = map(int, input().split())
输入n行字符串存在数组s中s = [input() for _ in range(n)]
n, m = map(int, input().split())
s = [input() for _ in range(n)]
ans = 0
for i in range(n):
for j in range(i + 1, n):
ok = True
for k in range(m):
if s[i][k] == 'x' and s[j][k] == 'x':
ok = False
break
if ok: ans += 1
print(ans)
n, m = map(int, input().split())
s = []
for i in range(n):
s.append(input())
ans = 0
for i in range(n):
for j in range(i + 1, n):
ok = True
for k in range(m):
if s[i][k] == 'x' and s[j][k] == 'x':
ok = False
break
if ok: ans += 1
print(ans)
C - String Delimiter
- 题意:给一个仅包含小写字母和逗号和双引号的字符串,保证双引号数量为偶数。定义第一个与第二个,第三个与第四个,…,双引号之间的字符为关闭的,将所有非关闭字符的逗号替换成句号并输出最终字符串
- 范围:N is an integer between 1 and 2×10^5 , inclusive.
- 写法:
python中字符串类型是不可修改的!因此s输入为lists = list(input())
String.join(任意类型?)
是将tuple中的所有东西变成字符串接在前面字符串后面
n = int(input())
s = list(input())
ok = True
for i in range(n):
if s[i] == '"':
ok = not ok
elif s[i] == ',' and ok:
s[i] = '.'
print("".join(s))