fork download
  1. """
  2. 466 名前:デフォルトの名無しさん[sage] 投稿日:2014/07/10(木) 02:35:06.94 ID:W+p4qrtw
  3. お題
  4. 昇順の数列A[a0,a1,..,an]とAの要素amを一つ指定する
  5. Aの要素からなる数列Bを与えて[am,am+1,..,an,a0,a1,..,am-1]の順番で整列させよう
  6. 入: A = [2,3,5,7,9], a = 2, B = [9,2,5]
  7. 出: [2,5,9]
  8. 入: A = [2,3,5,7,9], a = 9, B = [9,2,5]
  9. 出: [9,2,5]
  10. 入: A = [2,3,5,7,9], a = 5, B = [9,2,5]
  11. 出: [5,9,2]
  12. 入: A = [2,3,5,7,9], a = 3, B = [9,2,5,5,2]
  13. 出: [5,5,9,2,2]
  14. """
  15.  
  16. def f(A,a,B):
  17. ia = A.index(a)
  18. SA = A[ia:] + A[:ia]
  19. SB = sorted(B, key=lambda b: SA.index(b))
  20. print '-'*3
  21. print "入: A = {}, a = {}, B = {}".format(A,a,B)
  22. print "出: {} (A' = {})".format(SB,SA)
  23.  
  24. f(A = [2,3,5,7,9], a = 2, B = [9,2,5])
  25. f(A = [2,3,5,7,9], a = 9, B = [9,2,5])
  26. f(A = [2,3,5,7,9], a = 5, B = [9,2,5])
  27. f(A = [2,3,5,7,9], a = 3, B = [9,2,5,5,2])
  28.  
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
---
入: A = [2, 3, 5, 7, 9], a = 2, B = [9, 2, 5]
出: [2, 5, 9]  (A' = [2, 3, 5, 7, 9])
---
入: A = [2, 3, 5, 7, 9], a = 9, B = [9, 2, 5]
出: [9, 2, 5]  (A' = [9, 2, 3, 5, 7])
---
入: A = [2, 3, 5, 7, 9], a = 5, B = [9, 2, 5]
出: [5, 9, 2]  (A' = [5, 7, 9, 2, 3])
---
入: A = [2, 3, 5, 7, 9], a = 3, B = [9, 2, 5, 5, 2]
出: [5, 5, 9, 2, 2]  (A' = [3, 5, 7, 9, 2])