JonhsonPage.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace PPRazumovskiy.Pages
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для JonhsonPage.xaml
  19. /// </summary>
  20. public partial class JonhsonPage : Page
  21. {
  22. public JonhsonPage()
  23. {
  24. InitializeComponent();
  25. }
  26. private void getAnswerBtn_Click(object sender, RoutedEventArgs e)
  27. {
  28. try
  29. {
  30. int value1 = Convert.ToInt32(input1.Text.ToString());
  31. int value2 = Convert.ToInt32(input2.Text.ToString());
  32. int value3 = Convert.ToInt32(input3.Text.ToString());
  33. int value4 = Convert.ToInt32(input4.Text.ToString());
  34. int value5 = Convert.ToInt32(input5.Text.ToString());
  35. int value6 = Convert.ToInt32(input6.Text.ToString());
  36. int value7 = Convert.ToInt32(input7.Text.ToString());
  37. int value8 = Convert.ToInt32(input8.Text.ToString());
  38. int value9 = Convert.ToInt32(input9.Text.ToString());
  39. int value10 = Convert.ToInt32(input10.Text.ToString());
  40. int value11 = Convert.ToInt32(input11.Text.ToString());
  41. int value12 = Convert.ToInt32(input12.Text.ToString());
  42. if (value1 >= 0 && value2 >= 0 && value3 >= 0 && value4 >= 0 && value5 >= 0 &&
  43. value6 >= 0 && value7 >= 0 && value8 >= 0 && value9 >= 0 && value10 >= 0 &&
  44. value11 >= 0 && value12 >= 0)
  45. {
  46. int[,] array = new int[6, 2];
  47. array[0,0] = value1;
  48. array[0,1] = value2;
  49. array[1, 0] = value3;
  50. array[1, 1] = value4;
  51. array[2, 0] = value5;
  52. array[2, 1] = value6;
  53. array[3, 0] = value7;
  54. array[3, 1] = value8;
  55. array[4, 0] = value9;
  56. array[4, 1] = value10;
  57. array[5, 0] = value11;
  58. array[5, 1] = value12;
  59. int[,] answerArray = GlobalElement.Redistribution(array);
  60. answerArray = GlobalElement.SortArray(answerArray);
  61. int answer = GlobalElement.GetAnswer(answerArray);
  62. answerText.Text = answer.ToString();
  63. answer1.Text = answerArray[0, 0].ToString();
  64. answer2.Text = answerArray[0, 1].ToString();
  65. answer3.Text = answerArray[1, 0].ToString();
  66. answer4.Text = answerArray[1, 1].ToString();
  67. answer5.Text = answerArray[2, 0].ToString();
  68. answer6.Text = answerArray[2, 1].ToString();
  69. answer7.Text = answerArray[3, 0].ToString();
  70. answer8.Text = answerArray[3, 1].ToString();
  71. answer9.Text = answerArray[4, 0].ToString();
  72. answer10.Text = answerArray[4, 1].ToString();
  73. answer11.Text = answerArray[5, 0].ToString();
  74. answer12.Text = answerArray[5, 1].ToString();
  75. answerPanel.Visibility = Visibility.Visible;
  76. }
  77. else
  78. {
  79. MessageBox.Show("Решение задачи с такими входными данными невозможно");
  80. answerPanel.Visibility = Visibility.Hidden;
  81. }
  82. }
  83. catch (Exception ex)
  84. {
  85. MessageBox.Show("Упс, что-то пошло не так :(\nСообщение об ошибке: " + ex.Message);
  86. answerPanel.Visibility = Visibility.Hidden;
  87. }
  88. }
  89. }
  90. }