Q- oky a have a sentence wich is a list of words it can contains Lower case latters…
- User
Q- oky a have a sentence wich is a list of words it can contains Lower case latters (‘a’---> ‘z’) Digitis case (‘0’ → ‘9’) Hyphens (‘-’) Punctuations (‘!’,’.’,’,)) Space Q - we have the concept of “token” wich can be seen as valid word oky but need to verify these constrains :
It only contains lowercase , letters , hyphens , and/or punctuation (no digits ) Lzem yukon fem at most ( 0 or 1 ) hyphen , lzem zeda yukon (betwen) two lower case latters → example (“a-b” is a valid one ) → example (“-ab” is not a valid one) Lzemn yukon zeda fema at most one punctuation mark oky (0 or 1 ) → a can mawjouda lzemn ykon fe a5er the index oky → example (ab,) or (cd!) are valide ones → example (a!b) are not valid ones oky Q- what is the input &output format ?
-> sentence :string → output : int
Q- do have any approach or paradigm to solve this problem ?
I think of using divide and conquer approach to solve this problem → where each validation condition i will implement into a separate function oky and then combine them all into one main function oky
Q- i will start of the first one
It only contains lowercase letters, hyphens, and/or punctuation (no digits).
Q what is the input and output ? for this function
For the first helper function The input : word:string The output : bool
Q- how the logic will be
We will be initiate a set of digits = {‘0’,.....’9’} Traverse the input word char by char if Word[i] in set: Return False True
Q next we move the next (third helper function ) here
Q- what is the input&output format here ?
—> input: word : string —> output: bool
Q- what is the logic here ?
Step1 : we initiate a set called puncteation ('!', '.', and ',')
Step 2 : next we need to check the present of the any ponticuation
It need to present at most 1 time (0 or 1) We can initiate a hashmap = {} Compute the length of the word // traverse the chars of the word For i in range(n): If word[i] in set: If word[i] not in hashmap: hashmap[word[i]]=1 Else: hashmap[word[i]]+=1
Now we need to check the size of this hashmap if it’s >1 return false directly
Elif (we have verify it does not excede the first constrine at most of punctiaoiotnk) next we need to check word[n] in set : it true then we return True
Q- now form our work so far i want you need to generate a clean two peusudoCode for me oky
Sure, I can help you create clean pseudocode for the two helper functions you've described. Below are the pseudocode implementations for: Checking that a word contains no digits. Validating the punctuation constraints.
-
Helper Function: Check No Digits Function Name: hasNoDigits Description: This function verifies that the input word does not contain any digit characters ('0' to '9'). It returns True if the word has no digits, and False otherwise. Pseudocode: FUNCTION hasNoDigits(word: STRING) RETURNS BOOLEAN SET digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }
-
- Assistant