Find the repeating words in a sentence



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Find the repeating words in a sentence

Postby sparrrow » Sun Sep 20, 2015 10:49 am

Suppose my input sentence is:

"My friends who live in California are good. The people who work in my team are good."

My output will be:

my is present 2 times
in is present 2 times
are is present 2 times
good is present 2 times


While doing it with UNSTRING, I need to how many words are there present in the sentence.
But my input is given by user. So I do not know while coding that how many words will be present in the input sentence.
Please help to achieve this...
sparrrow
 
Posts: 1
Joined: Sun Sep 20, 2015 10:35 am
Has thanked: 0 time
Been thanked: 0 time

Re: Find the repeating words in a sentence

 

Re: Find the repeating words in a sentence

Postby Robert Sample » Sun Sep 20, 2015 5:18 pm

I'm not sure UNSTRING is a good choice here. Your sample input has two delimiters -- space and period. What other delimiters are allowed -- such as comma, semicolon, colon, question mark, exclamation point? Your program should find the next delimiter, get the word from the input variable into a holding variable, and then look at the word array to see if you've already got that word in the array. If not, add it to the array (you'll need to track how many entries you have in your word array), then go find the next delimiter. If I were doing this, I'd probably make a copy of the input and make the copy all lower case so capitalization doesn't cause any issues (your sample has My and my but they are counted together even though they aren't the same in EBCDIC).
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: Find the repeating words in a sentence

Postby BillyBoyo » Mon Sep 21, 2015 4:25 am

It is Master the Mainframe competition time, although that could be coincidence :-)

These users thanked the author BillyBoyo for the post:
ApexNC (Thu Aug 24, 2017 4:45 pm)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Find the repeating words in a sentence

Postby enrico-sorichetti » Mon Sep 21, 2015 12:14 pm

in my books it is called cheating ...
in the master of mainframes rules and regulations it is clearly stated that ...

By entering this Contest, you represent and warrant to Sponsor that each of your entries:
(i) are your own original creation and are 100% original,
(ii) are solely and exclusively owned by you;
(iii) does not infringe on third party rights,
(iv) has not won previous awards or has been posted on another Web site prior to submission and
(v) is suitable for publication.
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2644
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: Find the repeating words in a sentence

Postby BillyBoyo » Mon Sep 21, 2015 2:25 pm

When I challenged someone (elsewhere) previously, they replied that "you're allowed a mentor, and everyone else has a mentor. I have no mentor, so...". Anything actually in the rules on mentoring?

I like the "original" followed by "100% original" :-)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Find the repeating words in a sentence

Postby prino » Mon Sep 21, 2015 10:36 pm

sparrrow wrote:Suppose my input sentence is:

"My friends who live in California are good. The people who work in my team are good."

My output will be:

my is present 2 times
in is present 2 times
are is present 2 times
good is present 2 times


No, "my" is present once, and "My" is present once.
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy

These users thanked the author prino for the post:
ApexNC (Thu Aug 24, 2017 4:46 pm)
User avatar
prino
 
Posts: 536
Joined: Wed Mar 11, 2009 12:22 am
Location: Oostende, Belgium
Has thanked: 3 times
Been thanked: 21 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post