- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace Test
- {
- class Program
- {
-
- static bool Check(List<int> list1, List<int> list2)
- {
- int count = 0;
-
- foreach (var element in list2)
- {
- if(list1.IndexOf(element) > -1)
- {
- count++;
- }
- }
- return count < 2 ? true : false;
- }
-
- public static void Main(string[] args)
- {
- Dictionary<int, List<int>> dict = new Dictionary<int, List<int>>();
- dict.Add(1, new List<int>{1, 3});
- dict.Add(2, new List<int>{1, 8});
- dict.Add(3, new List<int>{2, 6});
- dict.Add(4, new List<int>{2, 10});
- dict.Add(5, new List<int>{3, 9});
- dict.Add(6, new List<int>{5, 7});
- dict.Add(7, new List<int>{6, 8});
- dict.Add(8, new List<int>{9, 10});
-
- Dictionary<int, List<int>> recipe = new Dictionary<int, List<int>>();
- recipe.Add(1, new List<int>{1, 4, 7});
- recipe.Add(2, new List<int>{2, 5, 7});
- recipe.Add(3, new List<int>{1, 6, 8});
- recipe.Add(4, new List<int>{3, 5, 9});
- recipe.Add(5, new List<int>{1, 5, 7, 10});
- recipe.Add(6, new List<int>{4, 8});
- recipe.Add(7, new List<int>{7, 9});
- recipe.Add(8, new List<int>{2, 4, 7});
- recipe.Add(9, new List<int>{4, 6, 9, 10});
- recipe.Add(10, new List<int>{2, 5});
-
- foreach (var element in recipe) //遍历处方
- {
- Console.WriteLine("处方{0}", element.Key);
- var entry1 = element.Value;
- foreach (var item in dict)
- {
- var entry2 = item.Value;
- if(!Check(entry1, entry2))
- {
- Console.WriteLine("处方{0}有错", element.Key);
- break;
- }
- }
- }
-
- Console.ReadKey(true);
- }
- }
- }
复制代码 |