Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- func merge(k, l, m int, base []int) {
- t := make([]int, m - k + 1)
- i := k
- j := l + 1
- h := 0
- for ; h < m - k + 1; h++ {
- if j <= m && (i == l + 1 || base[j] < base[i]) {
- t[h] = base[j]
- j++
- } else {
- t[h] = base[i]
- i++
- }
- }
- for i = 0; i <= h - 1; i++ {
- base[k+i] = t[i]
- }
- }
- func mergesortrec(low, high int, base []int) {
- if low < high {
- med := (low + high) / 2
- mergesortrec(low, med, base)
- mergesortrec(med + 1, high, base)
- merge(low, med, high, base)
- }
- }
- func mergesort(n int, base []int) {
- mergesortrec(0, n - 1, base)
- }
- func main() {
- var n, i int
- fmt.Scanf("%d\n", &n)
- a := make([]int, n)
- for i = 0; i < n; i++ {
- fmt.Scanf("%d", &a[i])
- }
- mergesort(n, a)
- for i = 0; i < n; i++ {
- fmt.Print(a[i], " ")
- }
- }
- ---------------------------------
- package main
- import "fmt"
- func main() {
- var n, m, i, j, x, y int
- fmt.Scanf("%d\n%d\n", &n, &m)
- matrix := make([][]int, n)
- for i = 0; i < m; i++ {
- fmt.Scanf("%d %d\n", &x, &y)
- if len(matrix[x]) == 0 {
- matrix[x] = make([]int, 10)
- matrix[x][0] = 2
- matrix[x][1] = 0
- }
- matrix[x][matrix[x][0]] = y
- matrix[x][0]++
- if x != y {
- if len(matrix[y]) == 0 {
- matrix[y] = make([]int, 10)
- matrix[y][0] = 2
- matrix[y][1] = 0
- }
- matrix[y][matrix[y][0]] = x
- matrix[y][0]++
- }
- }
- q := make(chan int, n)
- for i = 0; i < n; i++ {
- if matrix[i][1] == 0 {
- matrix[i][1] = 1
- q <- i
- for ; len(q) > 0; {
- x = <- q
- for j = 2; j < len(matrix[x]); j++ {
- if matrix[j][1] == 0 {
- matrix[j][1] = 1
- q <- j
- }
- }
- }
- }
- }
- }
- -------------------------------------
- package main
- import "fmt"
- import "strings"
- func parse(pos int, str string) int {
- var res strings.Builder
- cur := 0
- for ;; pos++ {
- x := str[pos]
- if cur == 2 {
- break
- }
- if x == '<' && cur == 0 {
- cur++
- }
- if x == '/' && cur == 1 {
- cur++
- }
- res.WriteRune(rune(x))
- //fmt.Println(res.String())
- }
- fmt.Println(res.String()[:res.Len() - 2])
- for ;; pos++ {
- if str[pos] == '>' {
- break
- }
- }
- return pos
- }
- func main() {
- var str string
- fmt.Scanf("%s", &str)
- pos := 0
- length := len(str)
- cur := 0
- for ; pos < length; pos++ {
- if cur == 2 {
- cur = 0
- pos = parse(pos, str)
- }
- if cur == 0 && str[pos] == '<' {
- cur++
- }
- if cur == 1 && str[pos] == '>' {
- cur++
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement