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
7 Réponses
+ 1
use a hashmap
+ 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...
+ 1
@manish rawat:
You're right...
( This definition has twisted my logical french mind ^^ )
+ 1
And I'm curious to know for what purpose this strange word property can be useful?!?
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.
0
@visph
look at description bro.
his definition of unique word is that the word in which character is not repeated!!!
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🤔