Cmar kabeer
A 2 parL1
Note
Comp||e make complle
kun prob|em 1 make runcpp
kun prob|em 2 make runperl
c|ean make clean
kC8LLM 1 (per| text match|ng)
l oseJ tbe Jlffeteot exomples ptovlJeJ lo tbe petl belp mooool lltslty l bteok Jowo tbe flle lloe by lloe
tbeo ose o ottoy to stote oll tbe wotJ lo tbot lloe wbeoevet tbete ls o motcb tbe wotJ ls stoteJ lo
oootbet ottoy to teptoJoce tbe tesolt lo tbe eoJ
"$usr$bln$perl w
read llne by llne
whlle()
spllL word of each llne lnLo an array
[word spllL( $_)
searchlng Lhe array of words of a llne
foreach $word2([word)
AnCPC8 ML1ACPA8S
lf($word2 $caL$) anchor meLachars
push([am1$word2)
lf($word2 $caL$$) anchor meLachars $
Cmar kabeer
A 2 parL1
push([am2$word2)
lf($word2 $caL$$) anchor meLachars$
push([am3$word2)
lf($word2 $bzaL$) characLer classes
push([am4$word2)
lf($word2 $bcaL$) word anchors
push([am3$word2)
lf($word2 $caLb$) word anchors
push([am6$word2)
maLch hhmmss formaL maLchlng varlables
lf ($word2 $(dd)(dd)(dd)$)
$hours $1
$mlnuLes $2
$seconds $3
push([am7$hours$mlnuLes$seconds)
Cmar kabeer
A 2 parL1
maLch uslng backreferences
lf ($word2 $(d)$)
lf ($word2 $11)
push ([am8 $word2)
sub rlnLLlsL
[prlnLelemenL [_
foreach $prlnLelemenL ([prlnLelemenL)
prlnL $prlnLelemenL n
prlnL n
prlnL Anchor MeLachars for words sLarLlng wlLh caLn
rlnLLlsL [am1
prlnL Anchor MeLachars for words LhaL maLch caLn
rlnLLlsL [am2
Cmar kabeer
A 2 parL1
prlnL Anchor MeLachars for word endlng wlLh caLn
rlnLLlsL [am3
prlnL CharacLer Classes for conaLlnlng bzaLn
rlnLLlsL [am4
prlnL Word anchors for word anchorlng caL aL Lhe sLarLn
rlnLLlsL [am3
prlnL Word anchors for word anchorlng caL aL Lhe endn
rlnLLlsL [am6
prlnL MaLchlng varlables Lo prlnL words LhaL maLch Llme varlablen
rlnLLlsL [am7
prlnL 8ackrefernclng for Llme Lo prlnL maLchlng seconds ln Llmen
rlnLLlsL [am8
Cmar kabeer
A 2 parL1
kC8LLM2
ets tbe flleoome fot tbe flle to be teoJ 1beo bteoks eocb lloe loto oo ottoy(vectot) ooJ petfotms
Jlffeteot cbecks
lnclude losLream
lnclude sLrlng
lnclude fsLream
lnclude csLdllb
lnclude cLlme
lnclude ssLream
lnclude vecLor
lnclude cmaLh
uslng namespace sLd
$$Lhe LoLal flelds are 14 ln Lhe flle whlch we are readlng
consL lnL ln1_1C1AL_llLLuS 14
$$deflnlng Lhe funcLlons
lnL lnL1lmeulfference(double fllghL1lme1 double fllghL1lme2)
vold LlmeConverL(ofsLream ouL lnL LoLal1lme)
bool conLlnulLyCheck(double long1double long2double laLL1double laLL2)
lnL maln()
Cmar kabeer
A 2 parL1
$$lnpuL SLream Lo lnpuL a LexL flle
lfsLream ls
sLrlng fllename
$$Dser lnpuLs fllename
couL LnLer Lhe name of flle whlch wlll serve as lnpuL
cln fllename
$$open Lhe flle
lsopen(fllenamec_sLr())
bool llleuoesnLLxlsL lsfall()
$$checks lf Lhe flle exlsLs
lf(llleuoesnLLxlsL)
couL llle doesnL exlsL endl
exlL(1)
$$creaLlgn log flle wlLh ouLpuL buffer
sLrlng flleouL fllenamesubsLr(fllenamerflnd()+1fllenamelengLh()) + log
ofsLream os (flleouLc_sLr())
lnL nfllghLs0 $$LoLal fllghLs
sLrlng llne $$Lo read llne uslng losLream
double Llme1 0
double long1 0
Cmar kabeer
A 2 parL1
double laLL1 0
whlle(geLllne(lsllne))
lf (llnesubsLr(03) ACM)
$$ reseLs Lhe counLer when a new header appears
os llne endl
nfllghLs 0
Llme1 0
long1 0
laLL1 0
else
$$geL llne lsLream
lsLrlngsLream lss(llne)
double lnpuLuaLa
$$lncrease fllghL slnce we found one mroe
nfllghLs++
vecLor double daLa
$$add daLa Lo vecLor
whlle (lss lnpuLuaLa)
daLapush_back(lnpuLuaLa)
Cmar kabeer
A 2 parL1
$$deLecLlng anomolles ln Lhe daLa
lf (daLaslze() ln1_1C1AL_llLLuS)
os Llne nfllghLs mlsslng daLa fleldsn
else
lnL LoLal1lme lnL1lmeulfference(Llme1daLa2)
lf (LoLal1lme 180 Llme1 " 0)
os Llne nfllghLs1 nfllghLs Llme gap
LlmeConverL(osLoLal1lme)
else
lf ("conLlnulLyCheck(long1daLa7laLL1daLa6) long1 " 0
laLL1 " 0)
os Llne nfllghLs1 nfllghLs daLa
conLlnulLy check falled endl
else
$$personal ouLpuL for good daLa
$$os uaLa quallLy check was succesful endl
Cmar kabeer
A 2 parL1
$$sLore Lhe Llme longlLude and laLlLude by exLracLlng lL from Lhe
vecLor
Llme1 daLa2
long1 daLa7
laLL1 daLa6
reLurn 0
lnL lnL1lmeulfference(double fllghL1lme1 double fllghL1lme2)
lnL LoLal1lme 0
lnL Lemp1lme 1
lnL fL1 sLaLlc_casL lnL (fllghL1lme1)
lnL fL2 sLaLlc_casL lnL (fllghL1lme2)
$$loops unLll one Llme ls exhausLed
whlle (fL1 0 fL2 0)
$$geLs Lhe Llme dlfference and adds lL Lo Lhe LoLal Llme dlfference
LoLal1lme LoLal1lme +( ((fL2 100) (fL1 100)) * Lemp1lme)
Lemp1lme Lemp1lme * 60
fL2 fL2 $ 100
Cmar kabeer
A 2 parL1
fL1 fL1 $ 100
reLurn LoLal1lme
vold LlmeConverL(ofsLream ouL lnL LoLal1lme)
$$dlvldlng Llme lnLo hours mlnuLes and seconds presenL lL correcLly
lf (LoLal1lme 3600)
ouL (LoLal1lme $ 3600) hours
LoLal1lme LoLal1lme 3600
lf (LoLal1lme 60)
ouL (LoLal1lme $ 60) mlnuLes
LoLal1lme LoLal1lme 60
ouL LoLal1lme seconds endl
bool conLlnulLyCheck(double long1double long2double laLL1double laLL2)
$$formula used ln Lhe pdf for gads LesLlng
reLurn (sqrL((long1long2)*(long1long2) + (laLL1laLL2)*(laLL1laLL2)) 3)