codinasion-archive / codinasion-monorepo

Community Monorepo
https://codinasion.org
MIT License
52 stars 170 forks source link

[Program]: Convert string to sentencecase #3714

Open harshraj8843 opened 1 year ago

harshraj8843 commented 1 year ago

Description

Write a program that converts a string to a sentence case.

Sentence case is a style of writing in which the first letter of the first word is capitalized, while all other letters are in lowercase. However, there are some exceptions to this rule. For example, proper nouns (such as names of people, places, organizations, etc.) and acronyms (such as NASA, FBI, etc.) should always be capitalized, regardless of their position in the sentence. The first word after a colon or a semicolon may also be capitalized.

Here is an example of a sentence in sentence case: "The quick brown fox jumps over the lazy dog." In this sentence, only the first letter of the first word is capitalized, while all other letters are in lowercase. However, if the sentence contains proper nouns or acronyms, they should also be capitalized. For example: "John and Jane went to New York to visit the Museum of Modern Art (MoMA)." In this sentence, the first letter of the first word, as well as the proper nouns "John", "Jane", "New York", and "Museum of Modern Art", and the acronym "MoMA" are capitalized.

Here are some examples of converting strings to sentence cases:

Example 1:

Input: "john and jane went to new york to visit the museum of modern art (moma)"
Output: "John and Jane went to New York to visit the Museum of Modern Art (MoMA)"

Example 2:

Input: "the united nations (un) is an international organization"
Output: "The United Nations (UN) is an international organization"

Example 3:

Input: "the cat is sleeping; however, the dog is awake"
Output: "The cat is sleeping; however, the dog is awake"

Hints

Hint 1: Start by taking two inputs: the input text and a list of fixed words (e.g., proper nouns, names, acronyms). The list should contain words that should always be capitalized.
Hint 2: Convert the entire input text to lowercase. Then, iterate through the list of fixed words and replace each occurrence in the text with its capitalized form.
Hint 3: Check if the list of fixed words is empty. If it is, it means that all words should be treated the same way. In this case, convert the entire text to lowercase and capitalize only the first letter of the first word.
Hint 4: Consider special cases, such as words that should always be capitalized after a colon or semicolon. Handle these cases separately to ensure correct sentence case formatting.

Tracking Issues

Pinklemonade33 commented 1 year ago

!assign

harshraj8843 commented 1 year ago

Hey @Pinklemonade33, !assign command is only for good first issue !!!

Please choose another issue.

Thanks for your interest in contributing to this project.