Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f22f5f6

Browse files
Create 7. PAT-1008-字符串处理
1 parent c0f0b6e commit f22f5f6

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎7. PAT-1008-字符串处理

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
@Problem_Link: https://www.nowcoder.com/pat/6/problem/4044
3+
4+
{W L D [B,C,J]}
5+
"""
6+
import sys
7+
8+
9+
def check_result(a, b):
10+
if a == b:
11+
return "D"
12+
if (a, b) == ("B", "C") or (a, b) == ("C", "J") or (a, b) == ("J", "B"):
13+
return "W"
14+
else:
15+
return "L"
16+
17+
def find_win_most(p):
18+
maxWin = max(p["WR"])
19+
if p["WR"][0] == maxWin:
20+
return "B"
21+
elif p["WR"][1] == maxWin:
22+
return "C"
23+
else:
24+
return "J"
25+
26+
if __name__ == "__main__":
27+
n = int(sys.stdin.readline().strip("\n"))
28+
mark = {"B":0, "C":1, "J":2}
29+
p1 = {'W':0, 'L':0, 'D':0, 'WR':[0, 0, 0]}
30+
p2 = {'W':0, 'L':0, 'D':0, 'WR':[0, 0, 0]}
31+
32+
for i in range(n):
33+
c1, c2 = sys.stdin.readline().strip("\n").split(" ")
34+
res = check_result(c1, c2)
35+
if res == "W":
36+
p1["W"] += 1
37+
p2["L"] += 1
38+
p1["WR"][mark[c1]] += 1
39+
elif res == "L":
40+
p1["L"] += 1
41+
p2["W"] += 1
42+
p2["WR"][mark[c2]] += 1
43+
else:
44+
p1["D"] += 1
45+
p2["D"] += 1
46+
47+
w1 = find_win_most(p1)
48+
w2 = find_win_most(p2)
49+
50+
print(p1["W"], p1["D"], p1["L"])
51+
print(p2["W"], p2["D"], p2["L"])
52+
print(w1, w2)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /