Can you help me with the task:
At the resistance base, we are creating a dictionary of all words. The previous dictionary was accidentally lost and is unrecoverable. The process of filling up the dictionary is very simple: we take random sentences, divide them into separate words, and add each to the dictionary. Your task is to write a program that takes a string as an input, separates that string by words, and outputs every word on a separate line. You can assume that word separators are these symbols: β β β,β β.β β!β β?β. Your program should not change any spelling or casing in the words. Be aware that the string can start with separators, and it can contain any number of separators between two words, as in the example below.
For example:
??Wow!!John , havenβt seen you for ages!
Wow
John
havenβt
seen
you
for
ages
My current solution is as in the following:
using System;
namespace Exam
{
class DivideString
{
static void Main()
{
string inputPhrase = Console.ReadLine();
char[] inputClean = new char[inputPhrase.Length];
bool isCarriageReturnDone = true;
for(int i=0; i<inputPhrase.Length; i++){
if(inputPhrase[i]==' ' || inputPhrase[i]==',' || inputPhrase[i]=='.' || inputPhrase[i]=='!' || inputPhrase[i]=='?'){
continue;
}
inputClean[i] = inputPhrase[i];
}
for(int i=0; i<inputClean.Length; i++){
if(inputClean[i] != '\0'){
isCarriageReturnDone = false;
Console.Write(inputClean[i]);
}
if(inputClean[i] == '\0' && !isCarriageReturnDone){
Console.WriteLine(" ");
isCarriageReturnDone = true;
}
}
}
}
}
However the system does not accept this solution. Can you help me out?
Thanks a lot