Esempio n. 1
0
def solution(genres, plays):
    global dic
    answer = []
    L=[]
    for i in range(len(genres)):
        if genres[i] in dic:
            dic[genres[i]]+=plays[i]
        else:
            dic[genres[i]]=plays[i]
        L.append((genres[i], plays[i], i))
        
    
       
    L.sort(key=cmp(f), reverse= True)

    temp2=''
    temp=''
    for i in range(len(genres)):
        if temp!=L[i][0]:
            answer.append(L[i][2])
            temp2= temp
            temp=L[i][0]
        elif temp2==L[i][0]: continue
        else:
            temp2=temp
            answer.append(L[i][2])
        
    return answer
Esempio n. 2
0
File: 1135.py Progetto: JannaKim/PS
def dfs3(v, t):
    global ans
    ans = max(ans, t)

    edge[v].sort(key=cmp(f2), reverse=True)

    for v2 in edge[v]:
        t += 1
        dfs3(v2, t)
Esempio n. 3
0
File: 1135.py Progetto: JannaKim/PS
def dfs(v, t):
    #print(v,t)
    mx = t
    for v2 in edge[v]:
        cnt[v2] = dfs2(v2, 0)

    edge[v].sort(key=cmp(f), reverse=True)

    for v2 in edge[v]:
        t += 1
        mx = max(dfs(v2, t), mx)
    return mx
Esempio n. 4
0
def pss_main():
    '''
    Print the user name, pid, pss, and the command line for all accessable
    processes in pss descending order.
    '''
    # Get the user name, pid, pss, and the command line information for all
    # processes that are accessable. Ignore processes where the permission is
    # denied.
    ls = []  # [(user, pid, pss, cmd)]
    for pid in filter(lambda x: x.isdigit(), os.listdir('/proc')):
        try:
            ls.append((owner_of_process(pid), pid, pss_of_process(pid),
                       cmdline_of_process(pid)))
        except IOError:
            pass

    # Calculate the max length of the user name, pid, and pss in order to
    # print them in aligned columns.
    userlen = 0
    pidlen = 0
    psslen = 0
    for (user, pid, pss, cmd) in ls:
        userlen = max(userlen, len(user))
        pidlen = max(pidlen, len(pid))
        psslen = max(psslen, len(str(pss)))

    # Get the width of the terminal.
    with os.popen('tput cols') as fp:
        term_width = int(fp.read().strip())

    # Print the information. Ignore kernel modules since they allocate memory
    # from the kernel land, not the user land, and PSS is the memory
    # consumption of processes in user land.
    fmt = '%%-%ds  %%%ds  %%%ds  %%s' % (userlen, pidlen, psslen)
    print(fmt % ('USER', 'PID', 'PSS', 'COMMAND'))
    for (user, pid, pss, cmd) in sorted(ls,
                                        key=cmp(lambda x, y: (y[2] - x[2]))):
        if cmd != '':
            print((fmt % (user, pid, pss, cmd))[:term_width - 1])
Esempio n. 5
0
n, m = map(int, input().split())

files = []
os = set()
for _ in range(n):
    file = input().split('.')
    # regmatch = re.match('(?P<name>\w+)\.(?P<ext>\w+)', file)
    # files.append((regmatch.group('name'), m.group('ext')))
    files.append(file)

for _ in range(m):
    input()


def compare(a, b):
    return ord(b) - ord(a)


def f(a, b):
    n = min(len(a), len(b))
    for i in range(n):
        res = compare(a[i], b[i])
        if res != 0:
            return res

    return 1 if len(a) < len(b) else -1


files.sort(key=cmp(lambda a, b: 1
                   if a[0] > b[0] else (-1 if a[0] < b[0] else f(a[1], b[1]))))
print(*[el[0] + '.' + el[1] for el in files], sep='\n')
Esempio n. 6
0
from functools import cmp_to_key as cmp
K = int(input())
n = int(input())
w = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]

cp = []
for i in range(n):
    cp.append((v[i] / w[i], i))

cp.sort(
    key=cmp(lambda a, b: w[b[1]] - w[a[1]] if a[0] == b[0] else a[0] - b[0]),
    reverse=True)


def cost_performance(i, size):
    s = size
    ans = 0
    for _cp, idx in cp:
        if idx >= i:
            if w[idx] >= s:
                ans += _cp * s
                return ans
            else:
                s -= w[idx]  # 여기서 음수로 빠질 일이 없을 것이다
                ans += v[idx]
    return ans  # 가방 다 못채웠는데 더 넣을게 없으면


mx = -1
x = [-1] * n
import sys
input = lambda: sys.stdin.readline().rstrip()
from functools import cmp_to_key as cmp
n = int(input())
sch = []
for _ in range(n):
    a, b = map(int, input().split())
    sch.append((a, b))

sch.sort(key=cmp(lambda a, b: a[0] - b[0] if a[1] == b[1] else a[1] - b[1]))

end = 0
cnt = 0
for st, ed in sch:
    if end <= st:
        cnt += 1
        end = ed

print(cnt)
from functools import cmp_to_key as cmp
import sys
input = lambda: sys.stdin.readline().strip()
s = input()
L = []
for idx, el in enumerate(s):
    L.append([idx, ord(el)])


def f(a, b):
    x = a
    y = b

    while x[1] == y[1]:
        if x[0] + 1 == len(s):
            return -1
        elif y[0] + 1 == len(s):
            return 1
        x = (x[0] + 1, ord(s[x[0] + 1]))
        y = (y[0] + 1, ord(s[y[0] + 1]))
    return x[1] - y[1]


L.sort(key=cmp(f))

for el in L:
    print(s[el[0]:])
Esempio n. 9
0
def largestNumber2(A):
    A = map(str,A)
    key = lambda a,b: 1 if a+b > b+a else -1
    A = sorted(A, key= cmp(key), reverse = True)
    return str(int(''.join(A)))
Esempio n. 10
0
from functools import cmp_to_key as cmp
N, K = map(int, input().split())
wv=[]
cp=[]
for i in range(N):
    wv.append(tuple(map(int, input().split())))
    cp.append((wv[i][1]/wv[i][0], i))

cp.sort(key= cmp(lambda a,b: wv[b[1]][0]-wv[a[1]][0] if a[0]==b[0] else a[0]-b[0]), reverse=True)
print(cp)

#가성비가 같다면 가벼우운순으로
X=[-1]*N
mx=-1
print(cp)
def cost_performance(i,size):
    #print('cp')
    s=size
    cnt=i
    ans=0
    for _cp, idx in cp:
        if idx>=cnt:
            if wv[idx][0]>=s:
                ans+=_cp*s
                #print('다채움', ans)
                return ans
            elif s>=0:
                s-=wv[idx][0]
                ans+=wv[idx][1]
                #print('ans줄임',ans)
    #print('다채움', ans)
Esempio n. 11
0
N = int(input())
L = [input() for _ in range(N)]


def Janna(a, b):
    for i in range(min(len(a), len(b))):
        if a[i] != b[i]:
            return dic[a[i].upper()] - dic[b[i].upper()]
    if len(a) >= len(b):
        return -1
    else:
        return 1


L.sort(key=cmp(Janna))
print(L)
'''
14
but
i
wonti
wont
hesitate
no
more
no
more
it
cannot
wait
Esempio n. 12
0
from functools import cmp_to_key as cmp
from sys import *

input = lambda: stdin.readline().rstrip()

N = int(input())
L = []
for i in range(N):
    a, b = input().split()
    L.append((int(a), b, i))

L.sort(key=cmp(lambda a, b: a[2] - b[2] if a[0] == b[0] else a[0] - b[0]))

[print(*el[:2]) for el in L]
Esempio n. 13
0
# https://leetcode.com/problems/largest-number/
# Given a list of non negative integers, arrange them such that they form the largest number.

# Approach (Libarary Fuction)

from functools import cmp_to_key as cmp
nums = [3,30,34,5,9]

# convert all elements of the list from int to string
nums = map(str, nums)

# we define a function that compares two string (a,b)
# we consider a bigger than b if a+b>b+a
# for example : (a="2",b="11") a is bigger than b because "211" >"112"
comp = lambda a,b:1 if a+b < b+a else -1 if a+b > b+a else 0

# sort the list descendingly using the comparing function we defined
# for example sorting this list ["2","11","13"] produce ["2","13","11"]
# Then concatenate
biggest = ''.join(sorted(nums, key=cmp(comp)))

# convert to int to remove leading zeroes
print (str(int(biggest)))

# Approach Custom operator
# Detailed : https://leetcode.com/problems/largest-number/solution/

def __lt__(x, y):
    return x+y > y+x