Advertisement
Ladies_Man

Минимальное расстояние

Mar 5th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.95 KB | None | 0 0
  1. package main
  2. import "fmt"
  3. import "github.com/skorobogatov/input"
  4.  
  5. func main() {
  6.     var x, y rune
  7.     var i, min, current, pos_x, pos_y int
  8.         min = 1000000
  9.        
  10.     str := input.Gets ()
  11.     input.Scanf("%c %c", &x, &y)
  12.  
  13.         var first, last int
  14.        
  15.         i = 0
  16.     for _, p := range str {
  17.                 i++
  18.         if p == x { //нашли x
  19.             pos_x = i
  20.         }
  21.         if p == y { //нашли y
  22.             pos_y = i
  23.         }
  24.                
  25.         if (p == x || p == y) && (0 < pos_x && 0 < pos_y) {
  26.                         current = pos_x - pos_y
  27.                         /*if 0 == current {
  28.                                 min = current
  29.                     goto exit
  30.                     }*/
  31.             if 0 > current {
  32.                 current *= -1
  33.             }
  34.             if current < min {
  35.                 min = current
  36.             }
  37.                         if 0 == (min - 1) {
  38.                                 goto exit
  39.                         }
  40.         }
  41.     }
  42.         exit:
  43.         min -= 1
  44.     fmt.Printf("%d", min)
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement