Advertisement
Guest User

Untitled

a guest
Nov 4th, 2014
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.09 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.   "fmt"
  5.   "os"
  6.   "bufio"
  7.   "bytes"
  8. )
  9.  
  10. func main() {
  11.   var tests int
  12.   scr := bufio.NewReader(os.Stdin)
  13.   fmt.Fscanln(scr,&tests)
  14.   for i := 0; i<tests; i++ {
  15.     matrix := read_matrix(scr)
  16.     find_matrix := read_matrix(scr)
  17.     found := true
  18.     for j := 0 ; j<len(matrix)-len(find_matrix)+1; j++ {
  19.       found = true
  20.       z := 0
  21.       for k:= range find_matrix{
  22.         if k == 0 {
  23.           z = bytes.Index(matrix[j+k],find_matrix[k])
  24.           if  z == -1 {
  25.             found = false
  26.             break
  27.           }
  28.         } else {
  29.           if !bytes.HasPrefix(matrix[j+k][z:],find_matrix[k]) {
  30.             found = false
  31.             break
  32.           }
  33.         }
  34.       }
  35.      
  36.       if found { break }
  37.     }
  38.     if found {
  39.       fmt.Println("YES")
  40.     } else {
  41.       fmt.Println("NO")
  42.     }
  43.   }
  44. }
  45.  
  46. func read_matrix(f *bufio.Reader)[][]byte {
  47.     var R,C int
  48.     fmt.Fscanln(f,&R,&C)
  49.     buf := make([][]byte,0,R)
  50.     for i:=0;i<R;i++ {
  51.       line, _ := f.ReadBytes('\n')
  52.       buf = append(buf,line[:len(line)-1])
  53.     }
  54.     return buf
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement