DSA - Pattern Matching

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Pro actical No.

D o t e : G//22
Am: Write o prognam or Patfenn Motchicg
5oftuaoe Requiod ova Online Cormpile

Prognom_Code
include<stdio.h>
Einclude<slring. h>
void se anch (Chan po, chan txt)
in M=strle n(pal)
nt N
stnlen (+xt)
fonCint 70 1<= N- M, ++)

on (j- o, js m i++)
f (t +57-po )
break

tpninlf CPottenn found o index od Nn

i n t main )

chan x t AABAACAADAABAAA BAA":


Chon po+ AABA
5onth pat, t x t
e t unn O
3
Oulpu
Patlenn found a ndex O
Poenn found at index 9
Paltenn found ot ndex 13
Conclusíon Patttnn Matehing ets yau ongonize he
code as
matehin 9 patdtn ns to be exetued
maieh is found tuhenthe pat4en
cASSMAte
Date:6I22
Page:
Pracico No. 1

Aim: WNeite a pnogeam fon Pateno Matchiag-


50fHuuaoe Requioed Tava Onliae Compilen.
Pnoqeam Code
iecudecstdio.b2
includesstníag.h
vaid scancb ( chan pot chan *fxt.

int ME Stnlea Cpat),


int N=6tnlen(txt
fon Lint i=o i=N-M:it
tatS
fon i0, jkM,jt)
iiftxtri+ i1=pat )
break

priatECCPatiro ound at index od \n D1

iat main)
char *xtAABAACAADAARAAA BAA
chan pat=AABA
SeanchLpattxt
peuna0
Output: Patlena ound at iodex o
Patkennfound ot iodtx
Patten aunol atedex 13
Conclu6lan Pa no Matchinq lets uo angaoize the cad as
metehin9 patlenns tbeexecukd when the
paffenn mateh is found.

You might also like