Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace Char
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] list = new string[]{"Coucou", "tout", "le", "monde", "Coucou"};
- string[] resultTri = tri(list);
- string[] resultSelectCar = selectLongCar(list, "ou");
- for (int i = 0; i < resultSelectCar.Length; i++)
- {
- Console.WriteLine($"{resultSelectCar[i]}\n");
- }
- }
- private static string[] tri(string[] list){
- string[] result = new string[list.Length];
- for (int i = 0; i < result.Length; i++)
- {
- string min = list[0];
- for (int j = 0; j < list.Length; j++)
- {
- if (list[j].Length < min.Length && !Array.Exists(result, element => element == list[j]))
- {
- min = list[j];
- }
- }
- result[i] = min;
- }
- return result;
- }
- private static string[] selectCar(string[] list, string text){
- List<string> resultArray = new List<string>();
- for (int i = 0; i < list.Length; i++)
- {
- if (list[i].Contains(text) && !resultArray.Exists(element => element == list[i]))
- {
- resultArray.Add(list[i]);
- }
- }
- string[] result = resultArray.ToArray();
- return result;
- }
- private static string[] selectLongCar(string[] list, string text){
- List<string> resultArray = new List<string>();
- int size = 0;
- for (int i = 0; i < list.Length; i++)
- {
- if (list[i].Contains(text) && size <= list[i].Length)
- {
- if (list[i].Length > size)
- {
- size = list[i].Length;
- resultArray.Clear();
- }
- resultArray.Add(list[i]);
- }
- }
- string[] result = resultArray.ToArray();
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement