1278A - Shuffle Hashing - CodeForces Solution


brute force implementation strings *1000

Please click on ads to support us..

Python Code:

t = int(input())

for t in range(t):
    p = list(input())
    h = list(input())
    a = 0
    b = int(len(p)-1)
    condition = False
    while condition == False:
        if sorted(h[a:b+1]) == sorted(p):
            print('YES')
            condition = True
        elif b+1 > len(h):
            print('NO')
            condition = True
        a += 1
        b += 1
 	 			   	  			    			 		  		 	

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int main(){ 
    int t;
    cin>>t;
    while(t--){
      string p,h,n;
      cin>>p>>h;
      int f=0;
      sort(p.begin(),p.end());
      int x=size(p),y=size(h);
      for(int i=0;i<=y-x;i++){
        n=h.substr(i,x);
        sort(n.begin(),n.end());
        if(n==p){
            f++;
            break;
        }
      }
      if(f){
        cout<<"YES"<<endl;
      }
      else{
        cout<<"NO"<<endl;
      }

    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

680B - Bear and Finding Criminals
1036E - Covered Points
1015D - Walking Between Houses
155B - Combination
1531A - Зингер | color
1678A - Tokitsukaze and All Zero Sequence
896A - Nephren gives a riddle
761A - Dasha and Stairs
1728B - Best Permutation
1728A - Colored Balls Revisited
276B - Little Girl and Game
1181A - Chunga-Changa
1728C - Digital Logarithm
1728D - Letter Picking
792B - Counting-out Rhyme
1195A - Drinks Choosing
5D - Follow Traffic Rules
1272A - Three Friends
1632D - New Year Concert
1400D - Zigzags
716C - Plus and Square Root
412A - Poster
844B - Rectangles
1591A - Life of a Flower
1398C - Good Subarrays
629A - Far Relative’s Birthday Cake
1166A - Silent Classroom
1000B - Light It Up
218B - Airport
1463B - Find The Array