• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
73%
SHARE
TWEET

# Untitled

a guest Jan 12th, 2017 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import sys
2.
3. ALPH = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "/", ":", ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
4.
5.
6. def check(start):
7.     n = start
8.     while n + 1 < len(s) and s[n + 1] != " ":
9.         a = s[n + 1]
10.         if s[n + 1] in ALPH:
11.             n += 1
12.         else:
13.             return -1
14.     if n - start > 6:
15.         return n + 1 #not include
16.     else:
17.         return -1
18.
19. l = int(input())
20. a = []
21. b = []
22. f = []
23. s = input()
24. if len(s) <= l:
25.     print(s)
26.     print(0)
27.     sys.exit()
28. n = s.count("http://")
29. start = s.find("http://")
30. f.append(start)
31. finish = check(start)
32. if finish != -1:
33.     a.append(start)
34.     b.append(finish)
35. for i in range(1, n):
36.     start = s.find("http://", f[-1] + 1, len(s))
37.     f.append(start)
38.     finish = check(start)
39.     if finish != -1:
40.         a.append(start)
41.         b.append(finish)
42. n = len(a)
43. delta_len = 0
44. for i in range(n):
45.     delta_len += b[i] - a[i] - 3
46. z = len(s)
47. x = delta_len
48. y = len(s) - l
49. delta = min(delta_len, len(s) - l)
50. ans = max(0, y - x)
51.
52. s_len = len(s)
53. s_ans = s[:a[0]]
54. p = 0
55. while delta > 0:
56.     if delta > b[p] - a[p] - 3:
57.         s_ans += "..." + s[b[p]:a[p + 1]]
58.         delta -= b[p] - a[p] - 3
59.     elif delta < b[p] - a[p] - 3:
60.         s_ans += s[a[p]:b[p] - delta - 3]
61.         s_ans += "..."
62.         s_ans += s[b[p]:]
63.         delta = 0
64.     else:
65.         s_ans += "..." + s[b[p]:]
66.         delta = 0
67.     p += 1
68.
69. print(s_ans)
70. print(ans)
RAW Paste Data
Top