Figuring out team groups based on match fixtures

using System;

using System.Collections.Generic;

using System.Collections;

using System.Text;

using System.Text.RegularExpressions;

using System.IO;

 

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            StreamReader sr = new StreamReader(@"C:\Fixture.txt");

            string str = sr.ReadLine();

            ArrayList groupList = new ArrayList();

            Regex reg = new Regex(" vs ");

            Console.WriteLine("==============");

            Console.WriteLine("T20 WC Fixture");

            Console.WriteLine("==============");

            while (str != null)

            {

                Console.WriteLine(str);

                string tempString = str;

                string[] teamArray = reg.Split(str);

                tempString = "";

                for (int i = 0; i < teamArray.Length; i++)

                {

                    if (i < teamArray.Length – 1)

                    {

                        tempString = tempString + teamArray[i] + " ";

                    }

                    else

                    {

                        tempString = tempString + teamArray[i];

                    }

                }

                if (groupList.Count == 0)

                {

                    groupList.Add(tempString);

                }

                else

                {

                    int flag = 0, i = 0;

                    for (i = 0; i < groupList.Count; i++)

                    {

                        for (int j = 0; j < teamArray.Length; j++)

                        {

                            if (groupList[i].ToString().Contains(teamArray[j]))

                            {

                                flag = 1;

                                break;

                            }

                        }

                        if (flag == 1)

                            break;

                    }

                    if (flag == 1)

                    {

                        for (int j = 0; j < teamArray.Length; j++)

                        {

                            if (!groupList[i].ToString().Contains(teamArray[j]))

                            {

                                string tempStr = groupList[i].ToString();

                                tempStr = tempStr + " " + teamArray[j];

                                groupList[i] = tempStr;

                            }

                        }

                    }

                    else

                    {

                        groupList.Add(tempString);

                    }

                }

                str = sr.ReadLine();

            }

            sr.Close();

            Console.WriteLine("=============");

            Console.WriteLine("T20 WC Groups");

            Console.WriteLine("=============");

            for (int i = 0; i < groupList.Count; i++)

            {

                Console.WriteLine(groupList[i]);

            }

        }

    }

}
 
==============
T20 WC Fixture
==============
Sri Lanka vs New Zealand
West Indies vs Ireland
India vs Afghanistan
Pakistan vs Bangladesh
South Africa vs India
Pakistan vs Australia
Sri Lanka vs Zimbabwe
West Indies vs England
New Zealand vs Zimbabwe
England vs Ireland
Bangladesh vs Australia
=============
T20 WC Groups
=============
Sri Lanka New Zealand Zimbabwe
West Indies Ireland England
India Afghanistan South Africa
Pakistan Bangladesh Australia
Press any key to continue . . .
Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s