110,535
社区成员
发帖
与我相关
我的任务
分享
class Program
{
static void Main(string[] args)
{
while (true)
{
Stopwatch timer = new Stopwatch();
timer.Reset();
HashSet<string> ht = new HashSet<string>();
timer.Start();
for (int i = 0; i <= 50000; i++)
{
string apps = "112,2,3,4,5,6,7,8,9,10,112,12,13,14,15,16,17,18,19,20,";
char[] appCharArr = apps.ToCharArray();
int length = appCharArr.Length;
int startIndex = 0;
char[] tempcharArr = new char[] { '\0', '\0', '\0', '\0' };
#region
for (int j = 0; j < length; j++)
{
char c = appCharArr[j];
if (c == ',')
{
string s = new string(tempcharArr);
if (!ht.Contains(s))
{
ht.Add(s);
}
startIndex = 0;
tempcharArr = new char[] { '\0', '\0', '\0', '\0' };
}
else
{
tempcharArr[startIndex] = c;
startIndex++;
}
}
#endregion
}
timer.Stop();
int count = ht.Count;
Console.WriteLine(timer.Elapsed.ToString());
Console.ReadLine();
}
}
}
static void Main(string[] args)
{
Stopwatch timer = new Stopwatch();
timer.Reset();
HashSet<int> big = new HashSet<int>();
bool[] small = new bool[100];
timer.Start();
string apps = "112,2,3,4,5,6,7,8,9,10,112,12,13,14,15,16,17,18,19,20,";
int number = 0;
for (int i = 0; i <= 500000; i++)
{
for (int j = 0; j < apps.Length; j++)
{
char c = apps[j];
if (c == ',')
{
if (number < 100)
{
small[number] = true;
}
else
{
big.Add(number);
}
number = 0;
}
else
{
number = number * 10 + (int) (c - '0');
}
}
}
timer.Stop();
for (int i = 0; i < small.Length; i++)
{
if (small[i])
{
Console.WriteLine(i);
}
}
foreach (var i in big)
{
Console.WriteLine(i);
}
Console.WriteLine("{0} ms", timer.Elapsed.TotalMilliseconds / 10);
}
}
foreach(string apps in value) apps.Split(',').toHash(hash)