using System;/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
public static void Main()
{
//
// TODO: Add constructor logic here
//
int[] a = { 3,3,3,6,6,9,9,12,12,12};
int[] b ={ 4,5,8,4,7,1,5,1,2,8};
int[] b1=new int[10];
int i, j;
// Console.WriteLine("{0}", a[0]); for (i = 0; i < b.Length; i++)
{
for (j = i + 1; j < b.Length; j++)
{
if (b[j] == b[i]) //使单的日期为0
{
b1[i] = b[i];
b1[j] = b[j];
}
}
} // Console.WriteLine("{0}", c[i]);
// Console.WriteLine("{0}",Class2.Class3(3,a));
for(i=0;i<b.Length;i++) //使单日期相对应的月为0所S1
{
if (b1[i] == 0)
{
int d = a[i];
for (j = 0; j < a.Length; j++)
{
if (a[j] == d)
{
a[j] = 0;
b1[j] = 0;
}
}
}
} for (i = 0; i < b.Length; i++)
{
for (j = i + 1; j < b.Length; j++)
{
if (b1[i] == b1[j]) //第二答的5月为0
{
b1[i] = 0;
b1[j] = 0;
a[i] = 0;
a[j] = 0;
} }
} for (i = 0; i < b.Length; i++)
{
for (j = i + 1; j < b.Length; j++)
{
if (a[i] ==a[j]) //第三答三月都为0
{
a[i] = 0;
a[j] = 0;
b1[i] = 0;
b1[j] = 0;
} }
}
for (i = 0; i < b.Length; i++)
{
Console.Write("{0}", b1[i]);
}
Console.WriteLine();
for (i = 0; i < b.Length; i++)
{
Console.Write("{0}", a[i]);
}
}}
/// Summary description for Class1
/// </summary>
public class Class1
{
public static void Main()
{
//
// TODO: Add constructor logic here
//
int[] a = { 3,3,3,6,6,9,9,12,12,12};
int[] b ={ 4,5,8,4,7,1,5,1,2,8};
int[] b1=new int[10];
int i, j;
// Console.WriteLine("{0}", a[0]); for (i = 0; i < b.Length; i++)
{
for (j = i + 1; j < b.Length; j++)
{
if (b[j] == b[i]) //使单的日期为0
{
b1[i] = b[i];
b1[j] = b[j];
}
}
} // Console.WriteLine("{0}", c[i]);
// Console.WriteLine("{0}",Class2.Class3(3,a));
for(i=0;i<b.Length;i++) //使单日期相对应的月为0所S1
{
if (b1[i] == 0)
{
int d = a[i];
for (j = 0; j < a.Length; j++)
{
if (a[j] == d)
{
a[j] = 0;
b1[j] = 0;
}
}
}
} for (i = 0; i < b.Length; i++)
{
for (j = i + 1; j < b.Length; j++)
{
if (b1[i] == b1[j]) //第二答的5月为0
{
b1[i] = 0;
b1[j] = 0;
a[i] = 0;
a[j] = 0;
} }
} for (i = 0; i < b.Length; i++)
{
for (j = i + 1; j < b.Length; j++)
{
if (a[i] ==a[j]) //第三答三月都为0
{
a[i] = 0;
a[j] = 0;
b1[i] = 0;
b1[j] = 0;
} }
}
for (i = 0; i < b.Length; i++)
{
Console.Write("{0}", b1[i]);
}
Console.WriteLine();
for (i = 0; i < b.Length; i++)
{
Console.Write("{0}", a[i]);
}
}}
using System.Collections.Generic;
using System.Text;namespace BirthdayGuesser
{
public class Birthday
{
public short month;
public short day;
public bool flag; // false -- singleton, true -- duplicated
public short sortFlag; // 0 -- not remove, 1 -- remove public Birthday(short _month, short _day)
{
month = _month;
day = _day;
flag = false;
sortFlag = 0;
}
} class Program
{
static void Main(string[] args)
{
List<Birthday> bList = new List<Birthday>();
// first put in all candidate days
inputDays(bList); // first round, only those months with all duplicated days will remain
int nCount = bList.Count;
int i, j, k;
for (i = 0; i < nCount; i++)
{
for (j = i + 1; j < nCount; j++)
{
if (bList[j].day == bList[i].day)
{
bList[j].flag = true;
bList[i].flag = true;
}
}
}
for (j = 0; j < nCount; j++)
{
if (bList[j].flag == false)
{ // singleton day
for (k = 0; k < nCount; k++)
{
if (bList[k].month == bList[j].month)
{
bList[k].sortFlag = 1;
}
}
}
}
bList.Sort(BComparison);
for (i = 0; i < nCount; i++)
{
if (bList[i].sortFlag == 1) break;
}
bList.RemoveRange(i, nCount - i);
// now print out the result
Console.WriteLine("Result after first round:");
foreach (Birthday bd in bList)
{
Console.WriteLine("Month: {0}, Day: {1}", bd.month, bd.day);
}
Console.WriteLine(); // second round, remove all duplicated days
nCount = bList.Count;
for (i = 0; i < nCount; i++)
{
for (j = i + 1; j < nCount; j++)
{
if (bList[j].day == bList[i].day)
{
bList[j].sortFlag = 1;
bList[i].sortFlag = 1;
}
}
}
bList.Sort(BComparison);
for (i = 0; i < nCount; i++)
{
if (bList[i].sortFlag == 1) break;
}
bList.RemoveRange(i, nCount - i);
Console.WriteLine("Result after second round:");
foreach (Birthday bd in bList)
{
Console.WriteLine("Month: {0}, Day: {1}", bd.month, bd.day);
}
Console.WriteLine(); // third round, only the month with the single day can remain
nCount = bList.Count;
for (i = 0; i < nCount; i++)
{
for (j = i + 1; j < nCount; j++)
{
if (bList[j].month == bList[i].month)
{
bList[j].sortFlag = 1;
bList[i].sortFlag = 1;
}
}
}
bList.Sort(BComparison);
for (i = 0; i < nCount; i++)
{
if (bList[i].sortFlag == 1) break;
}
bList.RemoveRange(i, nCount - i);
// now print out the result
Console.WriteLine("Answer:");
foreach (Birthday bd in bList)
{
Console.WriteLine("Month: {0}, Day: {1}", bd.month, bd.day);
}
}
static void inputDays(List<Birthday> aList)
{
aList.Add(new Birthday(3, 4));
aList.Add(new Birthday(3, 5));
aList.Add(new Birthday(3, 8));
aList.Add(new Birthday(6, 4));
aList.Add(new Birthday(6, 7));
aList.Add(new Birthday(9, 1));
aList.Add(new Birthday(9, 5));
aList.Add(new Birthday(12, 1));
aList.Add(new Birthday(12, 2));
aList.Add(new Birthday(12, 8));
}
static int BComparison(Birthday a, Birthday b)
{
return a.sortFlag - b.sortFlag;
} }
}
using System.Collections;namespace BirthdayGuesser
{
public class Birthday : IComparer
{
public short month;
public short day;
public bool flag; // false -- singleton, true -- duplicated
public short sortFlag; // 0 -- not remove, 1 -- remove public Birthday(short _month, short _day)
{
month = _month;
day = _day;
flag = false;
sortFlag = 0;
}
public Birthday()
{ } #region IComparer Members public int Compare(object x, object y)
{
return ((Birthday)x).sortFlag - ((Birthday)y).sortFlag;
} #endregion
} class Program
{
static void Main(string[] args)
{
ArrayList bList = new ArrayList();
// first put in all candidate days
inputDays(bList); // first round, only those months with all duplicated days will remain
int nCount = bList.Count;
int i, j, k;
for (i = 0; i < nCount; i++)
{
for (j = i + 1; j < nCount; j++)
{
if (((Birthday)bList[j]).day == ((Birthday)bList[i]).day)
{
((Birthday)bList[j]).flag = true;
((Birthday)bList[i]).flag = true;
}
}
}
for (j = 0; j < nCount; j++)
{
if (((Birthday)bList[j]).flag == false)
{ // singleton day
for (k = 0; k < nCount; k++)
{
if (((Birthday)bList[k]).month == ((Birthday)bList[j]).month)
{
((Birthday)bList[k]).sortFlag = 1;
}
}
}
}
bList.Sort(new Birthday());
for (i = 0; i < nCount; i++)
{
if (((Birthday)bList[i]).sortFlag == 1) break;
}
bList.RemoveRange(i, nCount - i);
// now print out the result
Console.WriteLine("Result after first round:");
foreach (Birthday bd in bList)
{
Console.WriteLine("Month: {0}, Day: {1}", bd.month, bd.day);
}
Console.WriteLine(); // second round, remove all duplicated days
nCount = bList.Count;
for (i = 0; i < nCount; i++)
{
for (j = i + 1; j < nCount; j++)
{
if (((Birthday)bList[j]).day == ((Birthday)bList[i]).day)
{
((Birthday)bList[j]).sortFlag = 1;
((Birthday)bList[i]).sortFlag = 1;
}
}
}
bList.Sort(new Birthday());
for (i = 0; i < nCount; i++)
{
if (((Birthday)bList[i]).sortFlag == 1) break;
}
bList.RemoveRange(i, nCount - i);
Console.WriteLine("Result after second round:");
foreach (Birthday bd in bList)
{
Console.WriteLine("Month: {0}, Day: {1}", bd.month, bd.day);
}
Console.WriteLine(); // third round, only the month with the single day can remain
nCount = bList.Count;
for (i = 0; i < nCount; i++)
{
for (j = i + 1; j < nCount; j++)
{
if (((Birthday)bList[j]).month == ((Birthday)bList[i]).month)
{
((Birthday)bList[j]).sortFlag = 1;
((Birthday)bList[i]).sortFlag = 1;
}
}
}
bList.Sort(new Birthday());
for (i = 0; i < nCount; i++)
{
if (((Birthday)bList[i]).sortFlag == 1) break;
}
bList.RemoveRange(i, nCount - i);
// now print out the result
Console.WriteLine("Answer:");
foreach (Birthday bd in bList)
{
Console.WriteLine("Month: {0}, Day: {1}", bd.month, bd.day);
}
}
static void inputDays(ArrayList aList)
{
aList.Add(new Birthday(3, 4));
aList.Add(new Birthday(3, 5));
aList.Add(new Birthday(3, 8));
aList.Add(new Birthday(6, 4));
aList.Add(new Birthday(6, 7));
aList.Add(new Birthday(9, 1));
aList.Add(new Birthday(9, 5));
aList.Add(new Birthday(12, 1));
aList.Add(new Birthday(12, 2));
aList.Add(new Birthday(12, 8));
}
}
}
结果如下:
Result after first round:
Month: 9, Day 1
Month: 9, Day 5
Month: 3, Day 8
Month: 3, Day 5
Month: 3, Day 4Result after second round:
Month: 3, Day 8
Month: 3, Day 4
Month: 9, Day 1Answer:
Month: 9, Day 1
连接啊