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;
- using System.Threading.Tasks;
- namespace _8_laba
- {
- class Program
- {
- static void Func1(string s)
- {
- Console.WriteLine("Введите подстроку: ");
- string n = Console.ReadLine();
- string[] p = s.Split(' ', ',');
- for (int i = 0; i < p.Length; i++)
- if (p[i].Contains(n)) //проверяет, содержится ли заданная подстрока в строке
- Console.WriteLine(p[i]);
- }
- static void Func2(string s)
- {
- Console.WriteLine("Введите число: ");
- int n = int.Parse(Console.ReadLine());
- string[] p = s.Split(' ', ',');
- for (int i = 0; i < p.Length; i++)
- if (p[i].Length <= n)
- Console.WriteLine(p[i]); //выводит только те слова, которые содержат н букв
- }
- static void Func3(string s)
- {
- string[] p = s.Split(' ', ',');
- for (int i = 0; i < p.Length; i++)
- if (char.IsUpper(p[i][0])) //выводит слова,начинающиеся с прописной буквы
- Console.WriteLine(p[i]);
- }
- static void Func4(string s)
- {
- string[] p = s.Split(' ', ',');
- for (int i = 0; i < p.Length; i++)
- {
- for (int j = 0; j < p[i].Length; j++)
- if (char.IsNumber(p[i][j])) //проверка, содержит ли сообщение цифру
- {
- Console.WriteLine(p[i]);
- break;
- }
- }
- }
- static void Func5(string s)
- {
- Console.WriteLine("Ввести подстроку: ");
- string n = Console.ReadLine();
- string[] p = s.Split(' ', ',');
- for (int i = 0; i < p.Length; i++)
- {
- if (p[i].EndsWith(n))
- p[i] = p[i].Remove(0); //удаляет все слова которые кончаются на заданный символ
- Console.Write(p[i] + " ");
- }
- }
- static void Func6(string s)
- {
- Console.Write("Ввести подстроку: ");
- char n = char.Parse(Console.ReadLine());
- string[] p = s.Split(' ', ',');
- for (int i = 0; i < p.Length; i++)
- {
- for (int j = 0; j < p[i].Length; j++)
- if (p[i][j] == n) //удаляет все слова, содержащие заданный символ
- {
- p[i] = p[i].Remove(0);
- break;
- }
- Console.Write(p[i] + " ");
- }
- }
- static string Func7(string s)
- {
- string[] p = s.Split(' ', ',');
- for (int i = 0; i < p.Length; i++)
- {
- if (p[i].Length == 1)
- {
- if (i != p.Length - 1) //удаляет все однобуквенные слова
- p[i] = p[i + 1];
- else
- p[i] = p[i].Remove(0);
- }
- }
- return String.Join(" ", p);
- }
- static string Func8(string s)
- {
- string[] p = s.Split(' ', ',');
- List<string> p1 = new List<string> { };
- foreach (var i in p)
- p1.Add(i);
- for (int i = 0; i < p1.Count; i++)
- {
- if (p1[i].Equals(i + 1))
- p1.Remove(i + 1);
- }
- foreach (var i in p1)
- {
- Console.WriteLine(i);
- }
- return String.Join(" ", p1);
- }
- static int Func9(string s)
- {
- Console.Write("Ввести подстроку: ");
- string substr = Console.ReadLine();
- int count = 0;
- string[] words = s.Split(' ', ',');
- for (int i = 0; i < words.Length; i++)
- {
- if (words[i].Equals(substr)) //удаляет все повторяющиеся слова в сообщении
- count++;
- }
- return count;
- }
- static int Func10(string s)
- {
- int count = 0;
- string[] words = s.Split(' ', ',');
- for (int i = 0; i < words.Length; i++)
- {
- bool isLower = true;
- for (int j = 0; j < words[i].Length; j++)
- {
- if (!Char.IsLower(words[i][j])) //подсчет слов, состоящих только из прописных букв
- {
- isLower = false;
- break;
- }
- }
- if (isLower)
- count++;
- }
- return count;
- }
- static void Func11(string s)
- {
- string[] words = s.Split(' ', ',');
- int max = 0;
- for (int i = 0; i < words.Length; i++)
- {
- if (words[max].Length < words[i].Length) //самое длинное слово сообщения
- max = i;
- }
- Console.WriteLine("Index: " + max + ". Word: " + words[max]);
- }
- static void Func12(string s)
- {
- string[] words = s.Split(' ', ',');
- int max = 0;
- for (int i = 0; i < words.Length; i++) //поиск всеъ самых длинных слов в сообщении
- {
- if (words[max].Length < words[i].Length)
- max = i;
- }
- for (int i = 0; i < words.Length; i++)
- {
- if (words[max].Length == words[i].Length)
- Console.WriteLine("Index: " + i + ". Word: " + words[i]);
- }
- }
- static void Func13(string s)
- {
- string[] words = s.Split(' ', ',');
- int max = 0;
- for (int i = 0; i < words.Length; i++) //Найти самое короткое слово сообщения
- {
- if (words[max].Length > words[i].Length)
- max = i;
- }
- Console.WriteLine("Index: " + max + ". Word: " + words[max]);
- }
- static void Func14(string s)
- {
- string[] words = s.Split(' ', ',');
- int max = 0;
- for (int i = 0; i < words.Length; i++) //Найти все самые короткие слова сообщения
- {
- if (words[max].Length > words[i].Length)
- max = i;
- }
- for (int i = 0; i < words.Length; i++)
- {
- if (words[max].Length == words[i].Length)
- Console.WriteLine("Index: " + i + ". Word: " + words[i]);
- }
- }
- static void Func16(string s)
- {
- string[] words = s.Split(' ', ',');
- List<string> wordsout = new List<string> { };
- int count = 0;
- for (int i = 0; i < words.Length; i++) //Вывести только те слова, которые встречаются в тексте ровно один раз
- {
- for (int j = 0; j < words.Length; j++)
- {
- if (words[i] == words[j] && i != j)
- count++;
- }
- if (count == 0)
- wordsout.Add(words[i]);
- count = 0;
- }
- for (int i = 0; i < wordsout.Count; i++)
- Console.WriteLine(wordsout[i]);
- }
- static void Func17(string s)
- {
- string[] words = s.Split(' ', ',');
- List<string> wordsout = new List<string> { };
- int count = 1;
- for (int i = 0; i < words.Length; i++) //Вывести только те слова, которые встречаются более n раз.
- {
- for (int j = 0; j < words.Length; j++)
- {
- if (words[i] == words[j] && i != j)
- count++;
- }
- if (count > 1)
- wordsout.Add(words[i]);
- count = 1;
- }
- for (int i = 0; i < wordsout.Count; i++)
- Console.WriteLine(wordsout[i]);
- }
- static string Func18(string s)
- {
- string[] words = s.Split(' ', ',');
- string tmp;
- for (int i = 0; i < words.Length; i++) //Вывести слова сообщения в алфавитном порядке.
- {
- for (int j = i + 1; j < words.Length; j++)
- {
- if (String.Compare(words[i], words[j]) == 1)
- {
- tmp = words[i];
- words[i] = words[j];
- words[j] = tmp;
- }
- }
- }
- return String.Join(" ", words);
- }
- static string Func19(string s)
- {
- string[] words = s.Split(' ', ',');
- string tmp;
- for (int i = 0; i < words.Length; i++) //Вывести слова сообщения в порядке возрастания их длин
- {
- for (int j = i + 1; j < words.Length; j++)
- {
- if (words[i].Length > words[j].Length)
- {
- tmp = words[i];
- words[i] = words[j];
- words[j] = tmp;
- }
- }
- }
- return String.Join(" ", words);
- }
- static void Main(string[] args)
- {
- Console.Write("Ввести строку: ");
- string str = Console.ReadLine();
- StringBuilder strB = new StringBuilder(str);
- //Func1(str);
- //Func2(str);
- //Func3(str);
- //Func4(str);
- //Func5(str);
- //Func6(str);
- //Console.WriteLine(Func7(str));
- //Console.WriteLine(Func8(str));
- Console.WriteLine(Func9(str));
- //Console.WriteLine(Func10(str));
- //Func11(str);
- //Func12(str);
- //Func13(str);
- //Func14(str);
- //Func16(str);
- //Func17(str);
- //Console.WriteLine(Func18(str));
- //Console.WriteLine(Func19(str));
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement