Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- /*
- * Дана строка текста, в которой слова разделены пробелами. Необходимо:
- - определить количество слов в строке;
- - найти самое короткое слово в строке, которое заканчивается на букву «а»;
- - вывести все слова, которые заканчиваются на букву «а».
- */
- string min;
- Console.WriteLine("Введите строку :");
- string text = Console.ReadLine();
- Console.WriteLine("Количество слов в строке :");
- string[] words = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- Console.WriteLine(words.Length);
- Console.WriteLine("Самое короткое слово в строке,которое заканчивается на букву 'a': ");
- for (int i = 0; i < words.Length; i++)
- {
- if (words[i][words[i].Length - 1] == 'а')
- {
- min = words[i];
- for (int j = i+1; j<words.Length;j++)
- {
- if(min.Length > words[j].Length)
- {
- if(words[j][words[j].Length - 1] == 'a')
- {
- min = words[j];
- }
- }
- }
- Console.WriteLine(min);
- break;
- }
- }
- Console.WriteLine("Слова,заканчивающиеся на букву 'а' :");
- for (int i = 0; i < words.Length; i++)
- {
- if (words[i][words[i].Length-1] == 'а')
- {
- Console.WriteLine(words[i]);
- }
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement