protected string Encode(string value)
        {
            UTF8Encoding encoding = new UTF8Encoding();

            switch (_DataType.Encoding)
            {
                case "BASE64": return Convert.ToBase64String(encoding.GetBytes(value));
                case "7BIT":
                case "8BIT":                
                    value = Regex.Replace(value, @"[^\r]\n", "\r\n");
                    value = Regex.Replace(value, @"\r[^\n]", "\r\n");

                    bool is7Bit = _DataType.Encoding.Equals("7BIT");

                    List<byte> data = new List<byte>(encoding.GetBytes(value));
                    for (int i = data.Count - 1; i >= 0; i--)
                    {
                        if (data[i] == 0)
                            data.RemoveAt(i);

                        if (is7Bit && data[i] > 127)
                            data.RemoveAt(i);
                    }

                    return encoding.GetString(data.ToArray());
                default:
                    return value;
            }
        }
 public Template CreateTemplate()
 {
     List<Cylinder> listCylinders = new List<Cylinder>();
     foreach (var middleMinutia in _minutiaeList)
     {
         int count = GetCountMinutia(middleMinutia);
         if (count >= MinNumberMinutiae)
         {
             Cylinder[] cylinders = CreateCylinders(middleMinutia);
             listCylinders.Add(cylinders[0]);
             listCylinders.Add(cylinders[1]);
         }
     }
     uint maxCount = GetMaxCount(listCylinders);
     for (int i = 1; i < listCylinders.Count; i += 2)
     {
         if (CylinderHelper.GetOneBitsCount(listCylinders[i].Values) >= 0.75 * maxCount)
         {
             continue;
         }
         listCylinders.RemoveAt(i--);
         listCylinders.RemoveAt(i--);
     }
     return new Template(listCylinders.ToArray());
 }
Example #3
0
 private void replaceTokensWithResult(List<MathToken> tokens,
     int indexOfOperator, int result)
 {
     tokens[indexOfOperator - 1] = new MathNumber(result.ToString());
     tokens.RemoveAt(indexOfOperator);
     tokens.RemoveAt(indexOfOperator);
 }
        public void Execute(List<string> arguments)
        {
            if (arguments.Count == 0)
            {
                ShowNoArgsMessage();
            }
            else
            {
                while (arguments.Count != 0)
                {
                    string key;
                    string value;

                    key = arguments[0];
                    arguments.RemoveAt(0);

                    if (arguments.ElementAtOrDefault(0) != null)
                    {
                        value = arguments[0];
                        arguments.RemoveAt(0);
                    }
                    else
                    {
                        value = "<null>";
                    }
                    Console.WriteLine("{0} - {1}", key, value);
                }
            }
        }
        public static List<int> merge(List<int> left, List<int> right)
        {
            List<int> result = new List<int>();
            while (left.Count > 0 && right.Count > 0)
            {
                if (left[0] < right[0])
                {
                    result.Add(left[0]);
                    left.RemoveAt(0);
                }
                else
                {
                    result.Add(right[0]);
                    right.RemoveAt(0);
                }
            }

            while (left.Count > 0)
            {
                result.Add(left[0]);
                left.RemoveAt(0);
            }
            while (right.Count > 0)
            {
                result.Add(right[0]);
                right.RemoveAt(0);
            }

            return result;
        }
Example #6
0
 public static List<GeoXYPoint> CoverageDistributePoint(GeoPolygon polygonPeak, double r)
 {
     List<GeoXYPoint> list = new List<GeoXYPoint>();
     GeoXYPoint centerPoint = new GeoXYPoint((polygonPeak.Right + polygonPeak.Left) / 2.0, (polygonPeak.Top + polygonPeak.Bottom) / 2.0);
     GeoXYPoint southwest = GetSouthWestPoint(polygonPeak.Left, polygonPeak.Right, polygonPeak.Top, polygonPeak.Bottom, centerPoint, r);
     GeoXYPoint northeast = GetNorthEastClutterPoint(polygonPeak.Left, polygonPeak.Right, polygonPeak.Top, polygonPeak.Bottom, centerPoint, r);
     list = InitialDistribute(southwest, northeast, r);
     int index = 0;
     while (index < list.Count)
     {
         if (!polygonPeak.IsPointInPolygon(list[index]))
         {
             list.RemoveAt(index);
             index--;
         }
         index++;
     }
     for (int i = 0; list.Count == 0; i++)
     {
         if (i >= polygonPeak.Points.Count)
         {
             return list;
         }
         list = InitialDistribute(polygonPeak.Points[i], northeast, r);
         for (index = 0; index < list.Count; index++)
         {
             if (!polygonPeak.IsPointInPolygon(list[index]))
             {
                 list.RemoveAt(index);
                 index--;
             }
         }
     }
     return list;
 }
Example #7
0
    private static List<int> Merge(List<int> leftList, List<int> rightList)
    {
        List<int> result = new List<int>();

        while (leftList.Count > 0 || rightList.Count > 0)
        {
            if (leftList.Count > 0 && rightList.Count > 0)
            {
                if (leftList[0] <= rightList[0])
                {
                    result.Add(leftList[0]);
                    leftList.RemoveAt(0);
                }
                else
                {
                    result.Add(rightList[0]);
                    rightList.RemoveAt(0);
                }
            }
            else if (leftList.Count > 0)
            {
                result.Add(leftList[0]);
                leftList.RemoveAt(0);
            }
            else if (rightList.Count > 0)
            {
                result.Add(rightList[0]);
                rightList.RemoveAt(0);
            }
        }

        return result;
    }
Example #8
0
        static void Main(string[] args)
        {
            string[] sequence = Console.ReadLine().Split();
            int kN = int.Parse(Console.ReadLine());

            int count = 1;
            List<int> seq = new List<int>();

            foreach (var item in sequence)
            {
                seq.Add(int.Parse(item));
            }
            int num = seq[0];
            for (int i = 1; i < seq.Count; i++)
            {
                if (num==seq[i])
                {
                    count++;
                    if (count==kN)
                    {
                        seq.RemoveAt(i);
                        seq.RemoveAt(i - 1);
                        count = 1;
                    }
                }

            }
        }
Example #9
0
        public static void Write(BinaryWriter writer, DateTime? time)
        {
            if (!time.HasValue)
            {
                // 1 byte long
                byte[] nullBytes = { 255 };
                writer.Write(nullBytes);
                return;
            }

            // byte is 1 byte long :)
            const byte size = 5;
            writer.Write(size);

            // Format:
            // 00:00:00 gives 05 00 00 00 00 00
            // 00:00:01 gives 05 80 96 98 00 00 -> 00 00 98 96 80 =    1.0000000
            // 00:01:00 gives 05 00 46 C3 23 00 -> 00 23 C3 46 00 =   60.0000000
            // 01:00:00 gives 05 00 68 C4 61 08 -> 08 61 C4 68 00 = 3600.0000000

            DateTime initTime = DateTime.Parse("00:00:00", System.Globalization.CultureInfo.InvariantCulture);
            TimeSpan span = time.Value - initTime;

            byte[] valueBytes = BitConverter.GetBytes((long)(span.TotalSeconds * 10000000));
            List<byte> bytes = new List<byte>(valueBytes);
            bytes.RemoveAt(7);
            bytes.RemoveAt(6);
            bytes.RemoveAt(5);
            writer.Write(bytes.ToArray());
        }
Example #10
0
        protected string FindArticle(List<string> w, List<string> t)
        {
            for (int i = 0; i < t.Count; ++i)
            {
                if ((t[i] == Tagger.Tags.Noun) || (t[i] == Tagger.Tags.NounPlural))
                {
                    if ((i > 0) && (t[i - 1] == Tagger.Tags.Determiner))
                    {
                        t.RemoveAt(i - 1);
                        w.RemoveAt(i - 1);
                        --i;
                    }

                    string s = w[i];
                    t.RemoveAt(i);
                    w.RemoveAt(i);

                    while ((i < t.Count) && ((t[i] == Tagger.Tags.Noun) || (t[i] == Tagger.Tags.NounPlural)))
                    {
                        s += " " + w[i];
                        t.RemoveAt(i);
                        w.RemoveAt(i);
                    }

                    return s;
                }
            }

            return string.Empty;
        }
Example #11
0
        public Path Cd(string newPath)
        {
            if (newPath.Length > 2 && newPath.Substring(0, 2) == "./")
            {
                newPath = newPath.Substring(2, newPath.Length - 2);
            }

            var paths = new List<string>();
            var newPathArray = newPath.Split('/');

            foreach (var word in this.CurrentPath.Substring(0, this.CurrentPath.Length))
            {
                paths.Add(word.ToString());
            }

            for (var counter = 0; counter < newPathArray.Length; counter = counter + 1)
            {
                if (newPathArray[counter] == "..")
                {
                    paths.RemoveAt(paths.Count - 2);
                    paths.RemoveAt(paths.Count - 1);
                }
                else if(newPathArray[counter].Length > 0)
                {
                    paths.Add("/");
                    paths.Add(newPathArray[counter]);
                }
            }

            
            return new Path(String.Join("", paths.ToArray()));
        }
Example #12
0
        public static List<string> CleanupList(List<string> l, bool cleanDupes)
        {
            // clone list first
            l = new List<string>(l);

            for (int x = 0; x < l.Count; x++)
            {
                l[x] = l[x].Trim();
                if (l[x].Length == 0)
                {
                    l.RemoveAt(x--);
                }
                else if (cleanDupes)
                {
                    for (int y = 0; y < x; y++)
                    {
                        if (l[y].Equals(l[x]))
                        {
                            l.RemoveAt(x--);
                            break;
                        }
                    }
                }
            }

            l.TrimExcess();

            return l;
        }
Example #13
0
        private void Callback(object obj)
        {
            if (sideVar >= 0)
            {
                ResetFilter ();
                List<GVar> _vars = new List<GVar>();

                if (sideVarLocation == VariableLocation.Global)
                {
                    _vars = vars;
                }
                else
                {
                    _vars = KickStarter.localVariables.localVars;
                }
                GVar tempVar = _vars[sideVar];

                switch (obj.ToString ())
                {
                case "Insert after":
                    Undo.RecordObject (this, "Insert variable");
                    _vars.Insert (sideVar+1, new GVar (GetIDArray (_vars)));
                    DeactivateAllVars ();
                    break;

                case "Delete":
                    Undo.RecordObject (this, "Delete variable");
                    _vars.RemoveAt (sideVar);
                    DeactivateAllVars ();
                    break;

                case "Move up":
                    Undo.RecordObject (this, "Move variable up");
                    _vars.RemoveAt (sideVar);
                    _vars.Insert (sideVar-1, tempVar);
                    break;

                case "Move down":
                    Undo.RecordObject (this, "Move variable down");
                    _vars.RemoveAt (sideVar);
                    _vars.Insert (sideVar+1, tempVar);
                    break;
                }
            }

            sideVar = -1;

            if (sideVarLocation == AC.VariableLocation.Global)
            {
                EditorUtility.SetDirty (this);
                AssetDatabase.SaveAssets ();
            }
            else
            {
                if (KickStarter.localVariables)
                {
                    EditorUtility.SetDirty (KickStarter.localVariables);
                }
            }
        }
        /// <summary>
        /// 创建一颗二叉树
        /// </summary>
        /// <param name="list"></param>
        /// <param name="root"></param>
        /// <returns></returns>
        public static TreeNode CreatBinaryTree(List<int> list, TreeNode root)
        {
            if (list.Count > 0)
            {
                root.left = new TreeNode(list[0]);
                list.RemoveAt(0);
            }
            else
            {
                return root;
            }

            if (list.Count > 0)
            {
                root.right = new TreeNode(list[0]);
                list.RemoveAt(0);
            }
            else
            {
                return root;
            }

            CreatBinaryTree(list, root.left);

            return root;
        }
Example #15
0
 void Start()
 {
     float cos = Mathf.Cos(maxAngle);
     MeshFilter MF = GetComponent<MeshFilter>();
     MeshCollider MC = GetComponent<MeshCollider>();
     if (MF == null || MC == null || MF.sharedMesh == null)
     {
         Debug.LogError("PlatformCollision needs a MeshFilter and a MeshCollider");
         return;
     }
     Mesh M = new Mesh();
     Vector3[] verts = MF.sharedMesh.vertices;
     List<int> triangles = new List<int>(MF.sharedMesh.triangles);
     for (int i = triangles.Count - 1; i >= 0; i -= 3)
     {
         Vector3 P1 = transform.TransformPoint(verts[triangles[i - 2]]);
         Vector3 P2 = transform.TransformPoint(verts[triangles[i - 1]]);
         Vector3 P3 = transform.TransformPoint(verts[triangles[i]]);
         Vector3 faceNormal = Vector3.Cross(P3 - P2, P1 - P2).normalized;
         if (Vector3.Dot(faceNormal, Vector3.up) <= cos)
         {
             triangles.RemoveAt(i);
             triangles.RemoveAt(i - 1);
             triangles.RemoveAt(i - 2);
         }
     }
     M.vertices = verts;
     M.triangles = triangles.ToArray();
     MC.sharedMesh = M;
 }
Example #16
0
        protected override void DefaultRemoveTargetsFilter(List<WoWObject> units)
        {
            for (int i = units.Count - 1; i >= 0; i--)
            {
                if (!units[i].IsValid)
                {
                    units.RemoveAt(i);
                    continue;
                }

                WoWUnit u = units[i].ToUnit();

                if (u.IsFriendly || u.Dead || u.IsPet() || !u.Combat || IsCrowdControlled(u))
                {
                    units.RemoveAt(i);
                    continue;
                }

                if (u.CurrentTarget != null)
                {
                    WoWUnit tar = u.CurrentTarget;
                    if (tar.IsPlayer && tar.IsHostile)
                    {
                        units.RemoveAt(i);
                        continue;
                    }
                }
            }
        }
        // case 1: StateMachine -> Default expression of StateMachine's variable -> ...
        // case 2: StateMachine -> InternalState -> ...
        public void ReplaceParentChainWithSource(Activity parentActivity, List<object> parentChain)
        {
            Activity lastActivity = parentChain[parentChain.Count - 1] as Activity;
            StateMachine stateMachine = (StateMachine)parentActivity;

            foreach (Variable variable in stateMachine.Variables)
            {
                if (variable != null && variable.Default == lastActivity)
                {
                    parentChain.Add(stateMachine);
                    return;
                }
            }

            if (parentChain.Count > 1)
            {
                // assume lastActivity is InternalState

                // remove InternalState
                parentChain.RemoveAt(parentChain.Count - 1);

                Activity targetActivity = (Activity)parentChain[parentChain.Count - 1];

                // the targetActivity will be available in the path
                parentChain.RemoveAt(parentChain.Count - 1);

                List<object> path = FindRelativePath(stateMachine, targetActivity);

                foreach (object pathObject in path)
                {
                    parentChain.Add(pathObject);
                }
            }
        }
Example #18
0
 public override void Read(List<byte> byteCode)
 {
     byteCode.RemoveAt(byteCode.Count - 1);
     byteCode.RemoveAt(byteCode.Count - 1);
     byteCode.RemoveAt(byteCode.Count - 1);
     byteCode.RemoveAt(byteCode.Count - 1);
 }
    public static List<string> Merge(List<string> left, List<string> right)
    {
        List<string> result = new List<string>();
        while (left.Count > 0 || right.Count > 0)
        {
            if (left.Count > 0 && right.Count > 0)
            {
                if (string.Compare(left[0], right[0]) < 0)
                {
                    result.Add(left[0]);
                    left.RemoveAt(0);
                }
                else
                {
                    result.Add(right[0]);
                    right.RemoveAt(0);
                }
            }
            else if (left.Count > 0)
            {
                result.Add(left[0]);
                left.RemoveAt(0);
            }
            else if (right.Count > 0)
            {
                result.Add(right[0]);
                right.RemoveAt(0);
            }
        }

        return result;
    }
Example #20
0
        private static List<Movement> FindPath(int r, int c, int dr, int dc, List<Movement> path, bool[,] blocks)
        {
            if (r == dr && c == dc)
                return path;

            blocks [r, c] = true;

            if (CanMove (r, c, Movement.DOWN, blocks)) {
                path.Add (Movement.DOWN);
                List<Movement> finalPath = FindPath (r + 1, c, dr, dc, path, blocks);
                if (finalPath != null)
                    return finalPath;
                else
                    path.RemoveAt (path.Count - 1);
            }

            if (CanMove (r, c, Movement.RIGHT, blocks)) {
                path.Add (Movement.RIGHT);
                List<Movement> finalPath = FindPath (r, c + 1, dr, dc, path, blocks);
                if (finalPath != null)
                    return finalPath;
                else
                    path.RemoveAt (path.Count - 1);
            }

            return null;
        }
        private static void ReorderWords(List<string> words)
        {
            for (int i = 0; i < words.Count; i++)
            {
                int position = words[i].Length % (words.Count + 1);
                words.Insert(position, words[i]);
                if (i <= position)
                {
                    words.RemoveAt(i);

                }
                else if (i > position)
                {
                    words.RemoveAt(i + 1);
                }

            }
            int maxLength = 0;
            foreach (var word in words)
            {
                if (word.Length > maxLength)
                {
                    maxLength = word.Length;
                }
               // Console.WriteLine(word);
            }

            Print(words, maxLength);
        }
Example #22
0
 static void Main()
 {
     int n = int.Parse(Console.ReadLine());
     List<string> input = new List<string>(n+1);
     int longestWord = 0;
     for (int i = 0; i < n; i++)
     {
         input.Add(Console.ReadLine());
         if (input[i].Length > longestWord) longestWord = input[i].Length;
     }
     int newPos = 0;
     for (int i = 0; i < n; i++)
     {
         newPos = (input[i].Length % (n + 1));
         input.Insert(newPos, input[i]);
         if (newPos < i)
             input.RemoveAt(i + 1);
         else
             input.RemoveAt(i);
     }
     StringBuilder sb = new StringBuilder();
     for (int i = 0; i < longestWord; i++)
         for (int j = 0; j < n; j++)
             if (i < input[j].Length) sb.Append(input[j][i]);
     Console.WriteLine(sb);
 }
        //Removes all irc server related text
        public static string Filter(string buf)
        {
            int i = 0, j = 0;
            List<char> charList = new List<char>();
            charList.AddRange(buf.ToCharArray());
            charList.RemoveAt(0);
            do
            {
                if (charList[i].Equals(':') & (j < 1))
                {
                    break;
                }
                else
                {
                    charList.RemoveAt(0);
                }

            } while (i < charList.Count);

            char[] text = charList.ToArray();
            buf = new string(text);
            charList = null;
            text = null;
            return buf;
        }
Example #24
0
		/// <summary>
		/// Removes any "." and ".." entries in the path.
		/// </summary>
		/// <param name="input"></param>
		/// <returns>The input filename with no parent or current directory references.</returns>
		public static string MakeCanonicalFileName(string input)
		{
			string drive = input.StartsWith(@"\\") ? @"\\" :System.IO.Path.GetPathRoot(input);
			string dirstring = drive == null ? input : input.Remove(0, drive.Length);
			string[] dirs = dirstring.Split(new char[] { System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar });
			List<string> dirList = new List<string>(dirs);

			for (int index = 0; index < dirList.Count; )
			{
				if (dirList[index] == "." || dirList[index] == "")
				{
					dirList.RemoveAt(index);
				}

				else if (dirList[index] == ".." && index > 0)
				{
					dirList.RemoveAt(index);
					dirList.RemoveAt(index - 1);
					--index;
				}

				else
				{
					++index;
				}
			}

			return drive + String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), dirList.ToArray());
		}
Example #25
0
 public static TileMapLayer Parse(List<string> rows)
 {
     var layer = new TileMapLayer ();
     while (rows.Count > 0 && rows [0].IndexOf ("}") == -1) {
         if (rows [0].IndexOf ("{") == -1) {
             var propName = rows [0].Substring (0, rows [0].IndexOf (":")).Trim ();
             var prop = "";
             foreach (var part in propName.Split("_".ToCharArray())) {
                 prop += part.Substring (0, 1).ToUpper () + part.Substring (1);
             }
             var value = rows [0].Substring (rows [0].IndexOf (":") + 1).Replace("\"","");
             var property = layer.GetType ().GetProperty (prop);
             property.SetValue(layer, Convert.ChangeType(value, property.PropertyType));
         } else {
             var propName = rows [0].Substring (0, rows [0].IndexOf ("{")).Trim ();
             switch (propName) {
             case "cell":
                 var cell = TileMapCell.Parse (rows);
                 layer.Cells.Add (cell);
                 break;
             }
         }
         rows.RemoveAt (0);
     }
     rows.RemoveAt (0);
     return layer;
 }
Example #26
0
    static List<int> Merge(List<int> left, List<int> right)
    {
        List<int> temp = new List<int>();

        while (left.Count > 0 || right.Count > 0)
        {
            if (left.Count > 0 && right.Count > 0)
            {
                if (left[0] <= right[0])
                {
                    temp.Add(left[0]);
                    left.RemoveAt(0);
                }
                else
                {
                    temp.Add(right[0]);
                    right.RemoveAt(0);
                }
            }
            else if (left.Count > 0)
            {
                temp.Add(left[0]);
                left.RemoveAt(0);
            }
            else
            {
                temp.Add(right[0]);
                right.RemoveAt(0);
            }
        }
        return temp;
    }
 /// <summary>
 ///     Formats the given parameters to call a function.
 /// </summary>
 /// <param name="parameters">An array of parameters.</param>
 /// <returns>The mnemonics to pass the parameters.</returns>
 public string FormatParameters(IntPtr[] parameters)
 {
     // Declare a var to store the mnemonics
     var ret = new StringBuilder();
     var paramList = new List<IntPtr>(parameters);
     // Store the first parameter in the ECX register
     if (paramList.Count > 0)
     {
         ret.AppendLine("mov ecx, " + paramList[0]);
         paramList.RemoveAt(0);
     }
     // Store the second parameter in the EDX register
     if (paramList.Count > 0)
     {
         ret.AppendLine("mov edx, " + paramList[0]);
         paramList.RemoveAt(0);
     }
     // For each parameters (in reverse order)
     paramList.Reverse();
     foreach (var parameter in paramList)
     {
         ret.AppendLine("push " + parameter);
     }
     // Return the mnemonics
     return ret.ToString();
 }
        private static void SecondTask(string[] cakes, int friends)
        {
            List<int> cakesSize = new List<int>();

            for (int i = 0; i < cakes.Length; i++)
            {
                cakesSize.Add(int.Parse(cakes[i]));
            }

            cakesSize.Sort();

            int bites = 0;

            while (cakesSize.Count != 0)
            {
                bites += cakesSize[cakesSize.Count - 1];
                cakesSize.RemoveAt(cakesSize.Count - 1);

                for (int i = 0; i < friends; i++)
                {
                    if (cakesSize.Count == 0)
                    {
                        break;
                    }

                    cakesSize.RemoveAt(cakesSize.Count - 1);
                }
            }

            Console.WriteLine(bites);
        }
Example #29
0
    static List<int> MakeMegre(List<int> left, List<int> right)
    {
        List<int> result = new List<int>();

        while (left.Count > 0 || right.Count > 0)
        {
            if (left.Count > 0 && right.Count > 0)
            {
                if (left[0] <= right[0])
                {
                    result.Add(left[0]);
                    left.RemoveAt(0);
                }
                else
                {
                    result.Add(right[0]);
                    right.RemoveAt(0);
                }
            }
            else if (left.Count > 0)
            {
                result.Add(left[0]);
                left.RemoveAt(0);
            }
            else if (right.Count > 0)
            {
                result.Add(right[0]);
                right.RemoveAt(0);
            }

            return result;
        }
    }
Example #30
0
        public static List<Tuple<Vector2, float>> merge(List<Tuple<Vector2, float>> Left, List<Tuple<Vector2, float>> Right)
        {
            // keep looping untill 1 list remains
            List<Tuple<Vector2, float>> result = new List<Tuple<Vector2, float>>();
            while (Left.Count > 0 && Right.Count > 0)
            {
                if (Left[0].Item2 < Right[0].Item2)
                {
                    result.Add(Left[0]);
                    Left.RemoveAt(0);
                }
                else
                {
                    result.Add(Right[0]);
                    Right.RemoveAt(0);
                }

            }
            while (Left.Count > 0)
            {
                result.Add(Left[0]);
                Left.RemoveAt(0);
            }
            while (Right.Count > 0)
            {
                result.Add(Right[0]);
                Right.RemoveAt(0);
            }
            return result;
        }