SHARE
TWEET

anagram

a guest Feb 21st, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def check(s,z):
  2.     temp=z
  3.     for i in s:
  4.         if i in temp:
  5.             temp.remove(i)
  6.         else:
  7.             return 0
  8.     return 1
  9. s=input()
  10. n=int(input())
  11. x=0; fc=""
  12. for i in range(n):
  13.     dir,diff=input().split()
  14.     if dir=="L":
  15.         x+=int(diff)
  16.         fc=fc+s[x]
  17.     elif dir=="R":
  18.         x-=int(diff)
  19.         fc=fc+s[x]
  20. z=list(fc)
  21. l=len(s); flag=0
  22. for i in range(l):
  23.     if flag==1:
  24.         break
  25.     for j in range(i+1+len(z),l):
  26.         flag=check(s[i:j+1],z)
  27.         if flag==1:
  28.             break
  29. print("YES") if flag==1 else print("NO")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top