IPetrov007

04_Extremums

Feb 27th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _04_Extremums
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<int> input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14. string word = Console.ReadLine();
  15.  
  16. List<int> result = new List<int>();
  17.  
  18. int minValue = int.MaxValue;
  19. int maxValue = int.MinValue;
  20. int sum = 0;
  21.  
  22. if (word == "Min")
  23. {
  24. for (int i = 0; i < input.Count; i++)
  25. {
  26. int element = input[i];
  27. string strElement = element.ToString();
  28.  
  29. int count = 0;
  30. while (count <= strElement.Length)
  31. {
  32. if (element < minValue)
  33. {
  34. minValue = element;
  35. }
  36. strElement = ShiftString(strElement);
  37. element = int.Parse(strElement);
  38. count++;
  39. }
  40. result.Add(minValue);
  41. sum += minValue;
  42. minValue = int.MaxValue;
  43. }
  44. }
  45. if (word == "Max")
  46. {
  47. for (int i = 0; i < input.Count; i++)
  48. {
  49. int element = input[i];
  50. string strElement = element.ToString();
  51.  
  52. int count = 0;
  53. while (count <= strElement.Length)
  54. {
  55. if (element > maxValue)
  56. {
  57. maxValue = element;
  58. }
  59. strElement = ShiftString(strElement);
  60. element = int.Parse(strElement);
  61. count++;
  62. }
  63. result.Add(maxValue);
  64. sum += maxValue;
  65. maxValue = int.MinValue;
  66. }
  67. }
  68. Console.WriteLine(string.Join(", ", result));
  69. Console.WriteLine(sum);
  70.  
  71.  
  72. }
  73. static string ShiftString(string str)
  74. {
  75. string firstCahr = str.Substring(0, 1);
  76. return str.Substring(1) + firstCahr;
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment