Beispiel #1
0
        public void inputProcess(string str)
        {
            string[]       input = str.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            Queue <string> q     = new Queue <string>();

            foreach (string cur in input)
            {
                q.Enqueue(cur);
            }
            int numOfFields = int.Parse(q.Peek());

            q.Dequeue();
            for (int i = 0; i < numOfFields; ++i)
            {
                string line = q.Peek();
                q.Dequeue();
                string[] tmp           = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                Field    f             = new Field(int.Parse(tmp[0]), int.Parse(tmp[1]), int.Parse(tmp[4]), int.Parse(tmp[3]), double.Parse(tmp[2]));
                int      numOfPackages = int.Parse(tmp[5]);
                for (int j = 0; j < numOfPackages; ++j)
                {
                    line = q.Peek();
                    q.Dequeue();
                    tmp = (line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                    int     packageType = int.Parse(tmp[2]);
                    Package p;
                    if (packageType == 1)
                    {
                        p = new Package1();
                    }
                    else
                    {
                        p = new Package2();
                    }
                    p.xCoord = int.Parse(tmp[0]);
                    p.yCoord = int.Parse(tmp[1]);
                    p.id     = tmp[3];
                    p.Price  = int.Parse(tmp[4]);
                    p.field  = i;
                    p.Date   = tmp[5];
                    f.add(new KeyValuePair <int, int>(p.xCoord, p.yCoord), p);
                }
                q.Dequeue();
                this.add(f);
            }
        }
Beispiel #2
0
        public bool setCons(string s)
        {
            string[] text = s.Split(new char[] { 'x' }, StringSplitOptions.RemoveEmptyEntries);
            if (text[0] != "1593572")
            {
                return(false);
            }
            lf.Clear();
            int l           = 1;
            int numOfFields = int.Parse(text[l++]);

            for (int i = 0; i < numOfFields; ++i)
            {
                string   line          = text[l++];
                string[] tmp           = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                Field    f             = new Field(int.Parse(tmp[0]), int.Parse(tmp[1]), int.Parse(tmp[4]), int.Parse(tmp[3]), double.Parse(tmp[2]));
                int      numOfPackages = int.Parse(tmp[5]);
                for (int j = 0; j < numOfPackages; ++j)
                {
                    line = text[l++];
                    tmp  = (line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                    int     packageType = int.Parse(tmp[2]);
                    Package p;
                    if (packageType == 1)
                    {
                        p = new Package1();
                    }
                    else
                    {
                        p = new Package2();
                    }
                    p.xCoord = int.Parse(tmp[0]);
                    p.yCoord = int.Parse(tmp[1]);
                    p.id     = tmp[3];
                    p.Price  = int.Parse(tmp[4]);
                    p.field  = i;
                    p.Date   = tmp[5];
                    f.add(new KeyValuePair <int, int>(p.xCoord, p.yCoord), p);
                }
                this.add(f);
            }
            return(true);
        }