Advertisement
Void-voiD

Untitled

Sep 18th, 2019
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func merge(k, l, m int, base []int) {
  6. t := make([]int, m - k + 1)
  7. i := k
  8. j := l + 1
  9. h := 0
  10. for ; h < m - k + 1; h++ {
  11. if j <= m && (i == l + 1 || base[j] < base[i]) {
  12. t[h] = base[j]
  13. j++
  14. } else {
  15. t[h] = base[i]
  16. i++
  17. }
  18. }
  19. for i = 0; i <= h - 1; i++ {
  20. base[k+i] = t[i]
  21. }
  22. }
  23.  
  24. func mergesortrec(low, high int, base []int) {
  25. if low < high {
  26. med := (low + high) / 2
  27. mergesortrec(low, med, base)
  28. mergesortrec(med + 1, high, base)
  29. merge(low, med, high, base)
  30. }
  31. }
  32.  
  33. func mergesort(n int, base []int) {
  34. mergesortrec(0, n - 1, base)
  35. }
  36.  
  37. func main() {
  38. var n, i int
  39. fmt.Scanf("%d\n", &n)
  40. a := make([]int, n)
  41. for i = 0; i < n; i++ {
  42. fmt.Scanf("%d", &a[i])
  43. }
  44. mergesort(n, a)
  45. for i = 0; i < n; i++ {
  46. fmt.Print(a[i], " ")
  47. }
  48. }
  49.  
  50. ---------------------------------
  51.  
  52. package main
  53.  
  54. import "fmt"
  55.  
  56. func main() {
  57. var n, m, i, j, x, y int
  58. fmt.Scanf("%d\n%d\n", &n, &m)
  59. matrix := make([][]int, n)
  60.  
  61. for i = 0; i < m; i++ {
  62. fmt.Scanf("%d %d\n", &x, &y)
  63. if len(matrix[x]) == 0 {
  64. matrix[x] = make([]int, 10)
  65. matrix[x][0] = 2
  66. matrix[x][1] = 0
  67. }
  68. matrix[x][matrix[x][0]] = y
  69. matrix[x][0]++
  70. if x != y {
  71. if len(matrix[y]) == 0 {
  72. matrix[y] = make([]int, 10)
  73. matrix[y][0] = 2
  74. matrix[y][1] = 0
  75. }
  76. matrix[y][matrix[y][0]] = x
  77. matrix[y][0]++
  78. }
  79. }
  80.  
  81. q := make(chan int, n)
  82. for i = 0; i < n; i++ {
  83. if matrix[i][1] == 0 {
  84. matrix[i][1] = 1
  85. q <- i
  86. for ; len(q) > 0; {
  87. x = <- q
  88. for j = 2; j < len(matrix[x]); j++ {
  89. if matrix[j][1] == 0 {
  90. matrix[j][1] = 1
  91. q <- j
  92. }
  93. }
  94. }
  95. }
  96. }
  97.  
  98.  
  99. }
  100.  
  101.  
  102. -------------------------------------
  103.  
  104. package main
  105.  
  106. import "fmt"
  107. import "strings"
  108.  
  109. func parse(pos int, str string) int {
  110. var res strings.Builder
  111. cur := 0
  112. for ;; pos++ {
  113. x := str[pos]
  114. if cur == 2 {
  115. break
  116. }
  117. if x == '<' && cur == 0 {
  118. cur++
  119. }
  120. if x == '/' && cur == 1 {
  121. cur++
  122. }
  123. res.WriteRune(rune(x))
  124. //fmt.Println(res.String())
  125. }
  126. fmt.Println(res.String()[:res.Len() - 2])
  127. for ;; pos++ {
  128. if str[pos] == '>' {
  129. break
  130. }
  131. }
  132. return pos
  133. }
  134.  
  135. func main() {
  136. var str string
  137. fmt.Scanf("%s", &str)
  138. pos := 0
  139. length := len(str)
  140. cur := 0
  141. for ; pos < length; pos++ {
  142. if cur == 2 {
  143. cur = 0
  144. pos = parse(pos, str)
  145. }
  146. if cur == 0 && str[pos] == '<' {
  147. cur++
  148. }
  149. if cur == 1 && str[pos] == '>' {
  150. cur++
  151. }
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement