[ACM]Q10327: Flip Sort
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q10327
{
class Program
{
static private int times, count; static private int[] iarr; static private bool ttof; static private char[] par = { ' ' };
static void Main(string[] args)
{
for (; ; )
{
labelt: Console.Write("times>>>");
ttof = int.TryParse(Console.ReadLine(), out times);
if (!ttof) goto labelt;
label: Console.Write("Integet>>>");
try
{
iarr = Array.ConvertAll<string, int>(Console.ReadLine().Split(par, StringSplitOptions.RemoveEmptyEntries), int.Parse);
if (iarr.Length != times) throw new Exception();
}
catch { goto label; }
count = 0;
for (int i = 1; i < times; i++)
{
if (iarr[i] < iarr[i - 1])
{
iarr[i] = iarr[i] ^ iarr[i - 1];
iarr[i - 1] = iarr[i] ^ iarr[i - 1];
iarr[i] = iarr[i] ^ iarr[i - 1];
count++;
}
if (i == times - 1)
{
i = 0;
times--;
}
}
Console.WriteLine("Minimum exchange operations :{0}", count);
}
}
}
}