using System;
using System.Linq;
public class RemoveMiddleWordFromString
{
public static void Main()
{
string str = "c# c c++ java rust";
string result = RemoveMiddleWord(str);
Console.WriteLine(result);
}
public static string RemoveMiddleWord(string input) {
// Split the string into words
string[] words = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
// If there are fewer than 3 words, nothing to remove
if (words.Length <= 2)
return input;
// Calculate the middle index
int midIndex = words.Length / 2;
// Create a new string without the middle word
return string.Join(" ",
words.Take(midIndex).Concat(words.Skip(midIndex + 1)));
}
}
/*
run:
c# c java rust
*/