awordisencountered,anewsetiscreatedforit.Thelinenumberisinsertedinanyevent.Sinceavaluecanbeinasetonlyonce,duplicatelinenumbersaresuppressedautomatically.
Afteralltheinputhasbeenread,thetableofwordsissortedbykey.Eachcorrespondingsetoflinenumbersissortedandthelinenumbersareappendedtothelinetobewritten.
Forexample,iftheinputfileis
OntheFuture!-howittells
Oftherapturethatimpells
Totheswingingandtheringing
Ofthebells,bells,bells-
Ofthebells,bells,bells,bells,
Bells,bells,bells-
Totherhymingandthechimingofthebells!
theoutputis
1OntheFuture!-howittells
2Oftherapturethatimpells
3Totheswingingandtheringing
4Ofthebells,bells,bells-
5Ofthebells,bells,bells,bells,
6Bells,bells,bells-
7Totherhymingandthechimingofthebells!
and3,7
bells4,5,6,7
chiming7
future1
how1
impells2
rapture2
rhyming7
3gnignir
節章說小的新最現呈 ᴡᴛ.ᴘᴏᴏ
3gnigniws
1sllet
2taht
7,5,4,3,2,1eht
tnemegdelwonkcA
.yreffeJtnilCdna,reklaWneK,dnesnwoTggerG,ygaB'OeelanaJ,llehctiMlliBybsnoitubirtnoctnecerhtiwrelpmaWevetSdnatnatuoCyraCfokrowehtnodesabsinoitatnemelpmitnerrucehT.tnempolevedstiotdetubirtnocevahsnosreprehtoynaM.relpmaWevetSdna,tnatuoCyraC,broKmiT,nosnaHevaDhtiwnoitaroballocnirohtuaehtehtybdengisedsawnocI
secnerefeR
.0991,noitidednoces,JN,sffilCdoowelgnE,.cnI,llaH-ecitnerP,egaugnaLgnimmargorPnocIehT,dlowsirG.T.MdnadlowsirG.E.R.1
.5991,872DPItnemucoDtcejorPnocIanozirAfo.vinUehT,egaugnaLgnimmargorPnocIehtfo3.9noisreV,dnesnwoT.M.GdnayreffeJ.L.C,dlowsirG.E.R.2
.5991,182DPItnemucoDtcejorPnocIanozirAfo.vinUehT,3.9noisreV;egaugnaLgnimmargorPnocIehtrofseitilicaFscihparG,yreffeJ.L.CdnadlowsirG.E.R,dnesnwoT.M.G.3