ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [🐉 백준 12단계] 정렬
    Algorithm/1일 1코테 2020. 12. 21. 14:43
    반응형

    백준 12단계

    [정렬]


    2750

    n = int(input())
    a = []
    for _ in range(n):
      a.append(int(input()))
    a.sort()
    for i in range(len(a)):
      print(a[i])

     

    2751

    import sys
    n = int(input())
    l =  []
    
    for _ in range(n):
        l.append(int(sys.stdin.readline()))
    
    l.sort()
    
    for i in l:
        print(i)

     

    10989

    import sys
    c = [0] * 10001
    n =  int(input())
    for _ in range(n):
      a = int(sys.stdin.readline())
      c[a] += 1
    
    for i in range(len(c)):
      if c[i] != 0:
        for _ in range(c[i]):
          print(i)
    

     

    2108

    import sys
    from collections import Counter
    
    n = int(sys.stdin.readline())
    
    answer = []
    
    for _ in range(n):
      answer.append(int(sys.stdin.readline()))
    
    answer.sort()
    
    # mean
    a = round(sum(answer)/len(answer))
    print(a)
    
    # 중앙값
    b = answer[(len(answer)//2)]
    print(b)
    
    # 최빈값
    # 직접 계산했더니 런타임 에러... counter 함수 사용
    d = Counter(answer).most_common()
    if len(d) > 1:
      if d[0][1] == d[1][1]:
        c = d[1][0]
      else:
        c = d[0][0]
    else:
      c = d[0][0]
    print(c)
    
    # 최댓값-최솟값
    d = max(answer) - min(answer)
    print(d)

     

    1427

    n = list(input())
    n.sort(reverse=True)
    print(int(''.join(n)))

     

    11650

    import sys
    
    t = int(input())
    l = []
    
    for _ in range(t):
        l.append(list(map(int, sys.stdin.readline().split())))
    
    l = sorted(l, key = lambda x : (x[0], x[1]))
    
    for i in l:
        print(i[0], i[1])
        

     

    11651

    import sys
    
    t = int(input())
    l = []
    
    for _ in range(t):
        l.append(list(map(int, sys.stdin.readline().split())))
    
    l = sorted(l, key = lambda x : (x[1], x[0]))
    
    for i in l:
        print(i[0], i[1])

     

    1181

    n = int(input())
    a = []
    for _ in range(n):
      a.append(input())
    a = list(set(a))
    a.sort(key=lambda x: (len(x), x))
    
    for i in a:
      print(i)

     

    10814

    import sys
    t = int(input()) # test case
    l = []
    
    for i in range(t):
        a, b = input().split()
        a = int(a)
        l.append([a,b,i])
    
    l = sorted(l, key = lambda x : (x[0], x[2]))
    
    for i in l:
        print(i[0], i[1])
    

     

    반응형

    댓글

Designed by Tistory.