Article View: cn.bbs.comp.database
Article #38Re: һ�����������
From: Galaxy��VOLUNTEERS��Database
Date: Thu, 22 Oct 2009 10:25
Date: Thu, 22 Oct 2009 10:25
113 lines
3644 bytes
3644 bytes
һ��ʼ������Ŀ��˼�ˡ�������ʡһ��
��������ͬ�������£�����C#�㶨�ˡ�����
TestData:
A 1
A 2
B 1
C 1
C 2
D 2
E 2
E 3
ExpectResult:
(A),(C)
(B),(A)
(B),(C)
(C),(A)
(D),(A)
(D),(C)
(D),(E)
namespace ConsoleApplication1
{
class CourseGroup
{
public string StudentID {get;set;}
public List<string> CourseCollections {get;set;}
}
class ResultPair
{
public string StudentAID { get; set; }
public string StudentBID { get; set; }
}
class Program
{
static void Main(string[] args)
{
DataClasses2DataContext db = new DataClasses2DataContext();
List<ResultPair> results = new List<ResultPair>();
List<E> data = db.Es.ToList();
var grouped = data.GroupBy(e => e.studentID).Select(e => new
CourseGroup{ StudentID = e.Key, CourseCollections =
e.Select(ee=>ee.courseID).OrderBy(ee=>ee).ToList() });
foreach (var stuGroup in grouped)
{
foreach (var otherStuGroup in grouped)
{
if (stuGroup.StudentID != otherStuGroup.StudentID )
{
bool flag =
CheckContainable(stuGroup.CourseCollections.ToList(),
otherStuGroup.CourseCollections.ToList());
if (flag)
{
results.Add(new ResultPair() { StudentAID =
stuGroup.StudentID, StudentBID = otherStuGroup.StudentID });
}
}
}
}
foreach (var result in results)
{
Console.WriteLine("(" + result.StudentAID + ")" + "," + "("
+ result.StudentBID + ")");
}
Console.Read ();
}
static bool CheckContainable(List<string> A, List<string> B)
{
if (A.Count > B.Count)
{
return false;
}
else
{
foreach (string courseID in A)
{
if (!B.Contains(courseID))
return false;
}
return true;
}
}
�� �� catsky (
��·��-��û�-Amoy lover) �Ĵ������ᵽ: ��: 3�ű?ѧ���S, �γ̱�C,ѡ�ι�ϵE
: дSQL,ѡ��ѧ���(s1,s2) ����s1����ѡ��s2�����пγ̡�
: ���������
--
Welcome to Database Board
��ӭ������ݿ��
http://bbs.sjtu.edu.cn/bbsdoc?board=database
[m[1;34m�� ��Դ:����ˮ˼Դ bbs.sjtu.edu.cn��[FROM: 207.46.55.30][m
Technical Details
Message-ID:
<4iUiVH$bCj@bbs.sjtu.edu.cn>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!193.201.147.68.MISMATCH!feeder.news-service.com!feeds.phibee-telecom.net!news.byr.edu.cn!news.shec6.edu.cn!SJTUShow Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!193.201.147.68.MISMATCH!feeder.news-service.com!feeds.phibee-telecom.net!news.byr.edu.cn!news.shec6.edu.cn!SJTU From: Dem.bbs@bbs.sjtu.edu.cn (Galaxy��VOLUNTEERS��Database) Newsgroups: cn.bbs.comp.database Subject: Re: һ����������� Date: 22 Oct 2009 10:25:16 GMT Organization: ��ˮ˼Դ Message-ID: <4iUiVH$bCj@bbs.sjtu.edu.cn> Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 8bit X-Filename: database/M.1256206817.A