题目:
r={0:"国学", 1:"离散数学", 2:"英语", 3:"Photoshop", 4:"java", 5:"高等代数"}
学生1的选课=[0,1,3,4]
学生2的选课=[2,3,4,5]
学生3的选课=[0,1,2,3,4]
求这3个学生共同选择了多少门一样的课?
写出C#代码。
推荐答案一:
int[] one = { 0, 1, 3, 4 };
int[] two = { 2, 3, 4, 5 };
int[] three = { 0, 1, 2, 3, 4 };
string[] course = { "国学", "离散数学", "英语", "Photoshop", "java", "高等代数" };
int[] result =newint[6];
foreach (int i in one)
result[i]++;
foreach (int i in two)
result[i]++;
foreach (int i in three)
result[i]++;
for (int i =0; i < result.Length; i++)
{
if (result[i] ==3)
Console.WriteLine(course[i]);
}
推荐答案二:
学生1的选课=110110
学生2的选课=001111
学生3的选课=111110
结果 = 110110 & 001111 & 111110
题目来源:http://topic.csdn.net/u/20111108/15/2735dde4-5984-4356-8b85-2f0ff0da7c95.html