Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. namespace Char
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string[] list = new string[]{"Coucou", "tout", "le", "monde", "Coucou"};
  12. string[] resultTri = tri(list);
  13. string[] resultSelectCar = selectLongCar(list, "ou");
  14.  
  15. for (int i = 0; i < resultSelectCar.Length; i++)
  16. {
  17. Console.WriteLine($"{resultSelectCar[i]}\n");
  18. }
  19. }
  20.  
  21. private static string[] tri(string[] list){
  22. string[] result = new string[list.Length];
  23.  
  24. for (int i = 0; i < result.Length; i++)
  25. {
  26. string min = list[0];
  27. for (int j = 0; j < list.Length; j++)
  28. {
  29. if (list[j].Length < min.Length && !Array.Exists(result, element => element == list[j]))
  30. {
  31. min = list[j];
  32. }
  33. }
  34.  
  35. result[i] = min;
  36. }
  37.  
  38. return result;
  39. }
  40.  
  41. private static string[] selectCar(string[] list, string text){
  42. List<string> resultArray = new List<string>();
  43.  
  44. for (int i = 0; i < list.Length; i++)
  45. {
  46. if (list[i].Contains(text) && !resultArray.Exists(element => element == list[i]))
  47. {
  48. resultArray.Add(list[i]);
  49. }
  50. }
  51.  
  52. string[] result = resultArray.ToArray();
  53.  
  54. return result;
  55. }
  56.  
  57. private static string[] selectLongCar(string[] list, string text){
  58. List<string> resultArray = new List<string>();
  59. int size = 0;
  60.  
  61. for (int i = 0; i < list.Length; i++)
  62. {
  63. if (list[i].Contains(text) && size <= list[i].Length)
  64. {
  65. if (list[i].Length > size)
  66. {
  67. size = list[i].Length;
  68. resultArray.Clear();
  69. }
  70. resultArray.Add(list[i]);
  71. }
  72. }
  73.  
  74. string[] result = resultArray.ToArray();
  75.  
  76. return result;
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement