// Метод возвращает список с номерами трех цветов, которые необходимо еще раз предъявить тестируемому // Метод возвращает Null, если таковых нет public static List<int> CheckAnswers(String answerStr) { if (String.IsNullOrWhiteSpace(answerStr)) { return null; } String[] items = answerStr.TrimEnd().Split(' '); List<LusherPairAnswerItem> answerItems = new List<LusherPairAnswerItem>(); for (int i = 0; i < 28; i++) { LusherPairAnswerItem lusherPairAnswerItem = new LusherPairAnswerItem(); String[] colorNumbers = items[i].Split(','); lusherPairAnswerItem.color_1 = Convert.ToInt32(colorNumbers[0]); lusherPairAnswerItem.color_2 = Convert.ToInt32(colorNumbers[1]); lusherPairAnswerItem.color_3 = Convert.ToInt32(colorNumbers[2]); answerItems.Add(lusherPairAnswerItem); } List<LusherPairColorItem> list = CountAndSortDescColors(answerItems.Select(x => x.color_3).ToArray()); List<int> specialNumbers = new List<int>(); int index = 0; while (index < list.Count - 2) { if (list[index].points == list[index + 1].points && list[index].points == list[index + 2].points) { specialNumbers.Add(list[index].number); specialNumbers.Add(list[index+1].number); specialNumbers.Add(list[index+2].number); break; } index++; } if (specialNumbers.Count == 0) { return null; } return specialNumbers; }
public static String GetColorString(String answerStr) { if (String.IsNullOrWhiteSpace(answerStr)) { return null; } String[] items = answerStr.TrimEnd().Split(' '); List<LusherPairAnswerItem> answerItems = new List<LusherPairAnswerItem>(); for (int i = 0; i < 28; i++) { LusherPairAnswerItem lusherPairAnswerItem = new LusherPairAnswerItem(); String[] colorNumbers = items[i].Split(','); lusherPairAnswerItem.color_1 = Convert.ToInt32(colorNumbers[0]); lusherPairAnswerItem.color_2 = Convert.ToInt32(colorNumbers[1]); lusherPairAnswerItem.color_3 = Convert.ToInt32(colorNumbers[2]); answerItems.Add(lusherPairAnswerItem); } LusherPairSpecialAnswerItem specialLusherPairAnswerItem = null; if (items.Count() > 28) { specialLusherPairAnswerItem = new LusherPairSpecialAnswerItem(); String[] colorNumbers = items[28].Split(','); specialLusherPairAnswerItem.color_1 = Convert.ToInt32(colorNumbers[3]); if (colorNumbers[0] == colorNumbers[3]) { specialLusherPairAnswerItem.color_2 = Convert.ToInt32(colorNumbers[1]); specialLusherPairAnswerItem.color_3 = Convert.ToInt32(colorNumbers[2]); } else if (colorNumbers[1] == colorNumbers[3]) { specialLusherPairAnswerItem.color_2 = Convert.ToInt32(colorNumbers[0]); specialLusherPairAnswerItem.color_3 = Convert.ToInt32(colorNumbers[2]); } else { specialLusherPairAnswerItem.color_2 = Convert.ToInt32(colorNumbers[0]); specialLusherPairAnswerItem.color_3 = Convert.ToInt32(colorNumbers[1]); } } List<LusherPairColorItem> list = CountAndSortDescColors(answerItems.Select(x => x.color_3).ToArray()); for (int i = 0; i < list.Count - 1; i++) { if (list[i].points == list[i+1].points) { int preferedColor = answerItems.FirstOrDefault( x => (x.color_1 == list[i].number && x.color_2 == list[i + 1].number) || (x.color_1 == list[i+1].number && x.color_2 == list[i].number)).color_3; if (preferedColor != list[i].number) { // replace LusherPairColorItem tmp = list[i]; list[i] = list[i + 1]; list[i + 1] = tmp; } } } if (specialLusherPairAnswerItem != null) { for (int i = 0; i < list.Count - 2; i++) { if (list[i].points == list[i + 1].points && list[i].points == list[i + 2].points) { LusherPairColorItem[] copy = list.ToArray(); list[i] = copy.FirstOrDefault(x => x.number == specialLusherPairAnswerItem.color_1); int preferedColor = answerItems.FirstOrDefault( x => (x.color_1 == specialLusherPairAnswerItem.color_2 && x.color_2 == specialLusherPairAnswerItem.color_3) || (x.color_1 == specialLusherPairAnswerItem.color_3 && x.color_2 == specialLusherPairAnswerItem.color_2)).color_3; if (preferedColor == specialLusherPairAnswerItem.color_2) { list[i + 1] = copy.FirstOrDefault(x => x.number == specialLusherPairAnswerItem.color_2); list[i + 2] = copy.FirstOrDefault(x => x.number == specialLusherPairAnswerItem.color_3); } else { list[i + 1] = copy.FirstOrDefault(x => x.number == specialLusherPairAnswerItem.color_3); list[i + 2] = copy.FirstOrDefault(x => x.number == specialLusherPairAnswerItem.color_2); } } } } String res = String.Empty; foreach (var item in list) { res += item.number + " "; } return res; }