Алгоритмическое мышление при решении задач (на примере языка C#). Шамшев А.Б - 46 стр.

UptoLike

Составители: 

46
public int getWordLength(int index) {
int res = 0;
for (int i = index; i < str.Length; i++) {
if (isSeparator(str[i])) {
break;
}
res = res + 1;
}
return res;
}
public string findLastWord() {
string[] words = str.Split(new char[] {' ', '.', ',', '!'},
StringSplitOptions.RemoveEmptyEntries);
if (words.Length == 0) {
throw new ApplicationException("В строке нет слов");
}
return words[words.Length - 1];
}
public void processString() {
string lastWord = findLastWord();
for (int i = 0; i < str.Length; i++) {
if (isSeparator(str[i])) {
continue;
}
int len = getWordLength(i);
string word = str.Substring(i, len);
if (needDelWord(word, lastWord)) {
str = str.Remove(i, len);
} else {
i = i + len;
}
}
}
public void mainAction() {
str = Console.ReadLine();
Console.WriteLine("Строка до обработки: " + str);
processString();
Console.WriteLine("Строка после обработки: " + str);
Console.ReadKey();
}
}
}