Movatterモバイル変換


[0]ホーム

URL:


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

Commitc323320

Browse files
author
calypso
authored
04/05 - python/ruby
04/05 - python/ruby
2 parentscddfb6e +77a161d commitc323320

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

‎2018/04_2/python/sqdorte.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
withopen('input','r')asraw:
2+
i=sorted(raw.read().strip().split('\n'))
3+
4+
guard=None
5+
sleeping=False
6+
start=None
7+
change=False
8+
9+
guards= {}
10+
11+
forlineini:
12+
minute=int(line[15:17])
13+
14+
ifline[19]=='f':
15+
sleeping=True
16+
start=minute
17+
elifline[19]=='w':
18+
sleeping=False
19+
change=True
20+
else:
21+
ifsleeping:
22+
sleeping=False
23+
change=True
24+
25+
guard=line[26:].split(' ')[0]
26+
27+
ifchange:
28+
foriinrange(start,minute):
29+
try:
30+
guards[guard][i]+=1
31+
exceptKeyError:
32+
try:
33+
guards[guard].update({i:1})
34+
exceptKeyError:
35+
guards[guard]= {i:1}
36+
change=False
37+
38+
h= []
39+
40+
forguardinguards:
41+
sleep=guards[guard]
42+
hour=list(zip(*sorted(zip(sleep.values(),sleep.keys()))))[1][-1]
43+
44+
h.append((sleep[hour], (hour,int(guard))))
45+
46+
guard,minute=list(zip(*sorted(h)))[-1][-1]
47+
print(guard*minute)

‎2018/05_1/python/sqdorte.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
withopen('input','r')asraw:
2+
polymer=raw.read().strip()
3+
4+
i=0
5+
6+
whilei!=len(polymer)-1:
7+
x,y=polymer[i],polymer[i+1]
8+
ifx.lower()==y.lower()andx!=y:
9+
polymer=polymer[:i]+polymer[i+2:]
10+
i-=1
11+
else:
12+
i+=1
13+
14+
print(len(polymer))

‎2018/05_2/python/sqdorte.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
frommathimportinf
2+
3+
withopen('input','r')asraw:
4+
polymer=raw.read().strip()
5+
6+
l=inf
7+
8+
forcharinset(polymer.lower()):
9+
poly=polymer.replace(char,'').replace(char.upper(),'')
10+
11+
i=0
12+
13+
whilei!=len(poly)-1:
14+
x,y=poly[i],poly[i+1]
15+
ifx.lower()==y.lower()andx!=y:
16+
poly=poly[:i]+poly[i+2:]
17+
i-=1
18+
else:
19+
i+=1
20+
21+
h=len(poly)
22+
23+
ifh<l:
24+
l=h
25+
26+
print(l)
File renamed without changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp