Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. public partial class Form1 : Form
  2. {
  3.     public Form1()
  4.     {
  5.         InitializeComponent();
  6.     }
  7.  
  8.     private void button1_Click(object sender, EventArgs e)
  9.     {
  10.         String symbols = textBoxFrom.Text;
  11.  
  12.         String result = Form1.maxLenghWordContainsSymbols(symbols);
  13.        
  14.         textBoxOutWord.Text = result;
  15.     }
  16.  
  17.     private static bool maxLenghWordContainsSymbols(String symbols)
  18.     {
  19.         String[] words = symbols.ToLower().Split(' ', StringSplitOptions.RemoveEmptyEntries);
  20.        
  21.         int maxLengthWordIndex = 0, maxLengthWord = words[0].Length;
  22.         for (int i = 1; i < words.Length; i++)
  23.         {
  24.             if (words[i].Length > maxLengthWord) {
  25.                 maxLengthWordIndex = i;
  26.                 maxLengthWord = words.Length;
  27.             }
  28.         }
  29.  
  30.         if (words[maxLengthWordIndex].Length % 2 == 1) {
  31.             int middleIndex = (words[maxLengthWordIndex].Length - 1) / 2;
  32.             return words[maxLengthWordIndex].Remove(middleIndex, 1);
  33.         }
  34.  
  35.         return "Самое длинное сообщение чётной длины";
  36.     }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement