[ACM]Q10474: Where is the Marble?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Q10474
{
class Program
{
static private int _n, _q, temp, qs; static private bool ntof, qtof, ttof, qstof, tof; static private int[] iarr;
static void Main(string[] args)
{
for (int co = 1; ; co++)
{
labeln: Console.Write("N>>>");
ntof = int.TryParse(Console.ReadLine(), out _n);
if (!ntof) goto labeln;
labelq: Console.Write("Q>>>");
qtof = int.TryParse(Console.ReadLine(), out _q);
if (!qtof) goto labelq;
int count = 0;
iarr = new int[_n];
while (count < _n)
{
labelt: Console.Write("ball Num>>>");
ttof = int.TryParse(Console.ReadLine(), out temp);
if (!ttof) goto labelt;
iarr[count] = temp;
count++;
}
labelqs: Console.Write("Question Num>>>");
qstof = int.TryParse(Console.ReadLine(), out qs);
if (!qstof) goto labelqs;
Stopwatch sw = new Stopwatch();
sw.Start();
tof = true;
Array.Sort(iarr);
for (int i = 0; i < iarr.Length; i++)
if (iarr[i] == qs) { Console.WriteLine("CASE# {0}:\n{1} found at {2}", co, qs, i + 1); tof = false; break; }
if (tof) Console.WriteLine("CASE# {0}:\n{1} not found", co, qs);
sw.Stop();
TimeSpan ts = sw.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);
}
}
}
}