Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- String symbols = textBoxFrom.Text;
- String result = Form1.maxLenghWordContainsSymbols(symbols);
- textBoxOutWord.Text = result;
- }
- private static bool maxLenghWordContainsSymbols(String symbols)
- {
- String[] words = symbols.ToLower().Split(' ', StringSplitOptions.RemoveEmptyEntries);
- int maxLengthWordIndex = 0, maxLengthWord = words[0].Length;
- for (int i = 1; i < words.Length; i++)
- {
- if (words[i].Length > maxLengthWord) {
- maxLengthWordIndex = i;
- maxLengthWord = words.Length;
- }
- }
- if (words[maxLengthWordIndex].Length % 2 == 1) {
- int middleIndex = (words[maxLengthWordIndex].Length - 1) / 2;
- return words[maxLengthWordIndex].Remove(middleIndex, 1);
- }
- return "Самое длинное сообщение чётной длины";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement