Write a program to input any sentence than count how many unique word is present in the sentence and than print? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Write a program to input any sentence than count how many unique word is present in the sentence and than print?

Ex. country . In which any letter is not repeated

24th Dec 2016, 8:21 AM
Abhinav Goyal
Abhinav Goyal - avatar
7 Answers
+ 1
use a hashmap
24th Dec 2016, 8:23 AM
Uran Kajtazaj
Uran Kajtazaj - avatar
+ 1
@manish rawat: You describe procedure for counting how many EACH LETTER IS USED, when the question ask of UNIQUE WORDS ;) @Abhinav Goyal: Use split() function to cut your string sentence into an array of words; Iterate on the array of words and fill a hashset with each word, so you'll get a list of unique words of your sentence; Get the size ( count ) of your hashset...
24th Dec 2016, 9:44 AM
visph
visph - avatar
+ 1
@manish rawat: You're right... ( This definition has twisted my logical french mind ^^ )
24th Dec 2016, 9:56 AM
visph
visph - avatar
+ 1
And I'm curious to know for what purpose this strange word property can be useful?!?
24th Dec 2016, 10:18 AM
visph
visph - avatar
0
m ake a function that takes string as parameter. then inside function u make a hashmap of a-z and set all to 0 initially. as you encounter each letter, increment corr seee corressponding hashmap value. finally in the function check for full hashmap , if ever u see value greater than or equal to 2 then return false else return true. call this function for all words of sentence and increment answer by 1 for each true. bonus... u can do it without hashmap too. just make array of 26 integers and think of them as a-z and do same as above.
24th Dec 2016, 9:29 AM
manish rawat
manish rawat - avatar
0
@visph look at description bro. his definition of unique word is that the word in which character is not repeated!!!
24th Dec 2016, 9:46 AM
manish rawat
manish rawat - avatar
0
@visph i also almost wrote solution that u wrote then suddenly i looked at the definition😂😂 question is not framed well though. u can name it something else why unique🤔
24th Dec 2016, 10:13 AM
manish rawat
manish rawat - avatar