当前位置: 首页>>代码示例>>C#>>正文


C# SortedDictionary.Remove方法代码示例

本文整理汇总了C#中SortedDictionary.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.Remove方法的具体用法?C# SortedDictionary.Remove怎么用?C# SortedDictionary.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortedDictionary的用法示例。


在下文中一共展示了SortedDictionary.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: cycle_check

        public string cycle_check(SortedDictionary<char, char> cycle)
        {
            var cycle_str = "A";
            var cycle_key = 'A';
            var cycle_value = cycle['A'];
            var cycle_length = "";

            while (cycle.Count != 1)
            {
                if (cycle_str.IndexOf(cycle_value) != -1)
                {
                    cycle.Remove(cycle_key);
                    cycle_key = cycle.ElementAt(0).Key;
                    cycle_value = cycle[cycle_key];
                    cycle_str += " " + cycle_key.ToString();
                }
                else
                {
                    cycle_str += cycle_value.ToString();
                    cycle.Remove(cycle_key);
                    cycle_key = cycle_value;
                    cycle_value = cycle[cycle_key];
                }
            }

            foreach (var el in cycle_str.Split(' '))
                cycle_length += el.Length + " ";

            return cycle_length;
        }
开发者ID:26Ghost,项目名称:Enigma,代码行数:30,代码来源:Form_Debug.cs

示例2: Solve

        public long Solve()
        {
            var primes = new Prime((int)DivisoNumbers);

            var sortedPrimes = new SortedDictionary<long, PrimeDivisors>();
            foreach (var prime in primes.PrimeList)
            {
                sortedPrimes.Add(prime, new PrimeDivisors(prime));
            }

            while (true)
            {
                var minkey = sortedPrimes.Keys.First();
                var maxKey = sortedPrimes.Keys.Last();

                var minValue = sortedPrimes[minkey];

                var newKey = minkey * minkey;
                if (newKey > maxKey)
                {
                    break;
                }
                sortedPrimes.Add(newKey, minValue.UpdatePower());

                sortedPrimes.Remove(minkey);
                sortedPrimes.Remove(maxKey);
            }

            return sortedPrimes.Select(
                primeDivisorse => (long)Math.Pow(primeDivisorse.Value.Prime, primeDivisorse.Value.Power) % Modulo
            ).Aggregate(
                1L, (current, coefficient) => (current * coefficient) % Modulo
            );
        }
开发者ID:joeazbest,项目名称:Euler,代码行数:34,代码来源:Problem500.cs

示例3: UploadCdnEntity

        public string UploadCdnEntity(SortedDictionary<string, object> requestParams)
        {
            string actionName = "UploadCdnEntity";

            string entityFile = requestParams["entityFile"].ToString();
            requestParams.Remove("entityFile");
            var file = new FileInfo(entityFile);
            if (!file.Exists)
            {
                throw new FileNotFoundException();
            }

            if (!requestParams.ContainsKey("entityFileMd5"))
            {
                FileStream md5_file = new FileStream(entityFile, FileMode.Open);
                System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
                byte[] retVal = md5.ComputeHash(md5_file);
                md5_file.Close();

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < retVal.Length; i++)
                {
                    sb.Append(retVal[i].ToString("x2"));
                }
                requestParams["entityFileMd5"] = sb.ToString();
            }

            return Call(actionName, requestParams, entityFile);
        }
开发者ID:GeniusQ,项目名称:qcloudapi-sdk-dotnet,代码行数:29,代码来源:Cdn.cs

示例4: Main

        private static void Main()
        {
            string readLine = Console.ReadLine();
            SortedDictionary<char, int> countsOfChars = new SortedDictionary<char, int>();
            int count = 1;

            for (int i = 0; i < readLine.Length; i++)
            {
                if (countsOfChars.ContainsKey(readLine[i]))
                {
                    int value = countsOfChars[readLine[i]];
                    countsOfChars.Remove(readLine[i]);
                    countsOfChars.Add(readLine[i], count + value);
                }
                else
                {
                    countsOfChars.Add(readLine[i], count);
                }
            }

            foreach (KeyValuePair<char, int> p in countsOfChars)
            {
                Console.WriteLine("{0}: {1} time/s", p.Key, p.Value);
            }
        }
开发者ID:Ilo-ILD,项目名称:AdvancedCSharp,代码行数:25,代码来源:Problem6CountSymbols.cs

示例5: KwayMerge

        private static void KwayMerge(IEnumerable<string> chunkFilePaths, string resultFilePath)
        {
            var chunkReaders = chunkFilePaths
                .Select(path => new StreamReader(path))
                .Where(chunkReader => !chunkReader.EndOfStream)
                .ToList();

            var sortedDict = new SortedDictionary<string, TextReader>();
            chunkReaders.ForEach(chunkReader => sortedDict.Add(chunkReader.ReadLine(), chunkReader));

            using (var resultWriter = new StreamWriter(resultFilePath, false))
                while (sortedDict.Any())
                {
                    var line = sortedDict.Keys.First();
                    var chunkReader = sortedDict[line];
                    sortedDict.Remove(line);

                    resultWriter.WriteLine(line);

                    var nextLine = chunkReader.ReadLine();
                    if (nextLine != null)
                    {
                        sortedDict.Add(nextLine, chunkReader);
                    }
                    else
                    {
                        chunkReader.Dispose();
                    }
                }
        }
开发者ID:anton-chernov,项目名称:SPPFirsLab,代码行数:30,代码来源:FileSort.cs

示例6: Main

        private static void Main()
        {
            Queue<string> grad = new Queue<string>();
            SortedDictionary<string, string> venueAndEvent = new SortedDictionary<string, string>();

            while (true)
            {
                string[] readLineComand = Console.ReadLine().Split(';').ToArray();
                if (readLineComand[0] == "END")
                {
                    for (int i = 0; i < grad.Count; i++)
                    {
                        Console.WriteLine(grad.Peek());
                        foreach (KeyValuePair<string, string> p in venueAndEvent)
                        {
                            Console.WriteLine("->{0}: {1}", p.Key, p.Value);
                        }
                    }
                    return;
                }

                if (venueAndEvent.ContainsKey(readLineComand[1]))
                {
                    string value = venueAndEvent[readLineComand[1]];
                    venueAndEvent.Remove(readLineComand[1]);
                    venueAndEvent.Add(readLineComand[1], value + value);
                }
                else if (true)
                {
                    grad.Enqueue(readLineComand[0]);
                    venueAndEvent.Add(readLineComand[1], readLineComand[2]);
                }
            }
        }
开发者ID:Ilo-ILD,项目名称:AdvancedCSharp,代码行数:34,代码来源:Problem8NightLife.cs

示例7: bNear_Click

 private void bNear_Click(object sender, RoutedEventArgs e) {
     SortedDictionary<string, string> d = new SortedDictionary<string, string>();
     foreach (string k in Settings.Default.Dirs.Split('\n')) d[k] = null;
     d[Pics] = null;
     d.Remove("");
     Directory.CreateDirectory(Pics);
     Settings.Default.Dirs = String.Join("\n", d.Keys.ToArray());
     Process.Start(Pics);
 }
开发者ID:HiraokaHyperTools,项目名称:PicSozai,代码行数:9,代码来源:SetteiWindow.xaml.cs

示例8: CalculateMedianSum

        public static int CalculateMedianSum(int[] numbers)
        {
            int medianSum = 0;
            var lowHeap = new SortedDictionary<int, int>();
            var highHeap = new SortedDictionary<int, int>();
            lowHeap.Add(numbers[0],0);
            medianSum += numbers[0];
            for (int index = 1; index < numbers.Length; index++)
            {
                int lowHeapMax = lowHeap.Last().Key;
                int current = numbers[index];
                // update heaps
                if (current < lowHeapMax)
                {
                    lowHeap.Add(current,0);
                }
                else
                {
                    highHeap.Add(current, 0);
                }

                bool mayRequireBalancing = (index + 1)%2 == 0;
                // balancing
                if (mayRequireBalancing && lowHeap.Count != highHeap.Count)
                {
                    if (lowHeap.Count > highHeap.Count)
                    {
                        lowHeapMax = lowHeap.Last().Key;
                        lowHeap.Remove(lowHeapMax);
                        highHeap.Add(lowHeapMax, 0);
                    }
                    else
                    {
                        int highHeapMin = highHeap.First().Key;
                        highHeap.Remove(highHeapMin);
                        lowHeap.Add(highHeapMin, 0);
                    }
                }

                // calculate median
                if (lowHeap.Count >= highHeap.Count)
                {
                    medianSum += lowHeap.Last().Key;
                }
                else
                {
                    medianSum += highHeap.First().Key;
                }
            }

            return medianSum;
        }
开发者ID:sejoker,项目名称:ProgrammingChallenges,代码行数:52,代码来源:MedianMaintenenceAlg.cs

示例9: GetShortestPath

    public NavPoint[] GetShortestPath(NavPoint start, NavPoint target)
    {
        HashSet<NavPoint> visited = new HashSet<NavPoint>();
        SortedDictionary<float,NavPoint> pq = new SortedDictionary<float, NavPoint>();
        Dictionary<NavPoint,NavPoint> cameFrom = new Dictionary<NavPoint, NavPoint>();
        Dictionary<NavPoint,float> scores = new Dictionary<NavPoint, float>();

        pq.Add(Vector3.Distance(target.position,start.position),start);
        scores.Add(start,Vector3.Distance(target.position,start.position));

        while(pq.Count > 0)
        {
            SortedDictionary<float,NavPoint>.KeyCollection.Enumerator keyEnumer = pq.Keys.GetEnumerator();
            keyEnumer.MoveNext();
            NavPoint np = pq[keyEnumer.Current];
            pq.Remove(keyEnumer.Current);

            if(IsGoal(np, target))
                return ReconstructPath(cameFrom,np);

            visited.Add(np);
            foreach(NavPoint neighbour in np.neighbours)
            {
                if(neighbour.gameObject.activeInHierarchy)
                {
                    if(visited.Contains(neighbour))
                        continue;
                    float estimate = scores[np] + Vector3.Distance(np.position,neighbour.position);
                    //if this is the first time we've seen this node
                    //or if we have a found a shorter path to it
                    if(!pq.ContainsValue(neighbour) || (scores.ContainsKey(neighbour) && estimate < scores[neighbour])) {
                        cameFrom[neighbour] = np;
                        scores[neighbour] = estimate;
                        try
                        {
                            pq.Add(estimate + Vector3.Distance(neighbour.position,target.position),neighbour);
                        } catch (System.ArgumentException e) {
                            //this means the key already exists i.e. there is already a distance that is this value
                            //this is real bad for A* that we can't have two things of the same priority but I'm just going
                            //to ignore it because GAME JAM
                            pq.Add(estimate + Vector3.Distance(neighbour.position,target.position)+Random.value/100,neighbour);
                        }
                    }
                }
            }
        }

        return null;
    }
开发者ID:EternalGB,项目名称:ldjam33,代码行数:49,代码来源:Pathfinder.cs

示例10: RemoveDuplicateLetters

        public string RemoveDuplicateLetters(string s)
        {
            StringBuilder sb = new StringBuilder();
            SortedDictionary<char, List<int>> dict = new SortedDictionary<char, List<int>>();
            int j = 0;
            foreach (char c in s)
            {
                List<int> list;
                if (!dict.TryGetValue(c, out list))
                {
                    dict.Add(c, list = new List<int>());
                }
                list.Add(j++);
            }

            SortedSet<int> set = new SortedSet<int>();
            foreach (var pair in dict)
            {
                set.Add(pair.Value[pair.Value.Count - 1]);
            }

            int pos = -1;
            char last = default(char);
            while (dict.Count > 0)
            {
                foreach (var pair in dict)
                {
                    int p = pair.Value[-1 * (pair.Value.BinarySearch(pos) + 1)];
                    if (p <= set.Min)
                    {
                        sb.Append(pair.Key);
                        pos = p;
                        last = pair.Key;
                        set.Remove(pair.Value[pair.Value.Count - 1]);
                        break;
                    }
                }
                dict.Remove(last);
            }

            return sb.ToString();
        }
开发者ID:card323,项目名称:algorithms,代码行数:42,代码来源:Program.cs

示例11: ShortestProcessNext

 /// <summary>
 /// initiates the object and runs the scheduler on given processes.
 /// </summary>
 /// <param name="pList">List of processes</Process></param>
 /// <param name="quantumTime">represented in seconds</param>
 public ShortestProcessNext(List<Process> pList, double quantumTime)
 {
     this.pList = pList.OrderBy(o => o.ArrivalTime).ToList();
     TimeSpan currentTime = this.pList[0].ArrivalTime;
     List<Process> tmplist = new List<Process>(this.pList);
     arrivedPList = new SortedDictionary<TimeSpan, Process>();
     log = new Logger();
     while (tmplist.Count > 0 && tmplist[0].ArrivalTime <= currentTime)
     {
         arrivedPList.Add(tmplist[0].ServiceTime - tmplist[0].SpentTime, tmplist[0]);
         tmplist.RemoveAt(0);
     }
     while (tmplist.Count > 0 || arrivedPList.Count > 0)
     {
         if (arrivedPList.Count > 0)
         {
             Process p = arrivedPList[arrivedPList.Keys.Min()];
             arrivedPList.Remove(arrivedPList.Keys.Min());
             if (!p.Started)
             {
                 p.StartTime = currentTime;
                 p.Started = true;
             }
             TimeSpan spenttime = TimeSpan.FromSeconds(quantumTime);
             p.SpentTime += spenttime;
             log.Log(currentTime, p.Pid.ToString(), p.SpentTime, (p.ServiceTime >= p.SpentTime) ? (p.ServiceTime - p.SpentTime) : TimeSpan.FromSeconds(0));
             currentTime += spenttime;
             if (p.SpentTime >= p.ServiceTime)
                 p.EndTime = p.StartTime + p.SpentTime;
             else
                 arrivedPList.Add(p.ServiceTime - p.SpentTime, p);
         }
         else
             currentTime = tmplist[0].ArrivalTime;
         while (tmplist.Count > 0 && tmplist[0].ArrivalTime <= currentTime)
         {
             arrivedPList.Add(tmplist[0].ServiceTime - tmplist[0].SpentTime, tmplist[0]);
             tmplist.RemoveAt(0);
         }
     }
 }
开发者ID:silverfoxy,项目名称:ProcessScheduler,代码行数:46,代码来源:ShortestProcessNext.cs

示例12: findSum

 public long findSum(int[] m, int R)
 {
     List<int> desc = new List<int>();
     for (int i = 0; i < m.Length; i++)
     {
         if (i == 0 || m[i] < desc[desc.Count - 1]) { desc.Add(m[i]); }
     }
     SortedDictionary<int, List<int>> resets  =new SortedDictionary<int, List<int>>();
     foreach (int i in desc)
     {
         var basis = new List<int>();
         basis.Add(i);
         resets.Add(i, basis);
     }
     int curMin = desc[desc.Count - 1];
     int val = 1;
     long total = 0;
     for (int i = 1; i <= R; i++)
     {
         if (i == curMin)
         {
             val = 0;
             List<int> basis = resets[curMin];
             resets.Remove(curMin);
             foreach (int b in basis)
             {
                 List<int> other;
                 if (!resets.TryGetValue(curMin + b, out other))
                 {
                     other = new List<int>();
                     resets[curMin + b] = other;
                 }
                 other.Add(b);
             }
             curMin = resets.First().Key;
         }
         total += val;
         val++;
     }
     return total;
 }
开发者ID:Tilps,项目名称:Stash,代码行数:41,代码来源:Q1.cs

示例13: Main

        static void Main()
        {
            var courses = new SortedDictionary<string, List<Student>>();
            string separator = " | ";
            var filePath = "../../../students.txt";
            using (StreamReader reader = new StreamReader(filePath))
            {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();

                    var courseStartIndex = line.LastIndexOf(separator) + separator.Length;
                    var course = line.Substring(courseStartIndex, line.Length - courseStartIndex).Trim();

                    var familyNameStartIndex = line.IndexOf(separator) + separator.Length;
                    var familyNameLength = line.Length - course.Length - separator.Length - familyNameStartIndex;
                    var familyName = line.Substring(familyNameStartIndex, familyNameLength).Trim();

                    var firstName = line.Substring(0, familyNameStartIndex - separator.Length).Trim();

                    var students = new List<Student>();
                    if (courses.ContainsKey(course))
                    {
                        students = courses[course];
                    }

                    var student = new Student(firstName, familyName);
                    students.Add(student);

                    courses.Remove(course);
                    courses.Add(course, students);
                }

                foreach (var pair in courses)
                {
                    var students = pair.Value.OrderBy(s => s.FamilyName).ThenBy(s => s.FirstName).ToList();
                    Console.WriteLine("{0} : {1}", pair.Key, string.Join(", ", students));
                }
            }
        }
开发者ID:NK-Hertz,项目名称:Telerik-Academy-2015,代码行数:40,代码来源:StartUp.cs

示例14: Main

    public static void Main()
    {
        // Read the input
        Console.WriteLine("Enter amount");
        int amount = int.Parse(Console.ReadLine());
        Console.WriteLine("Enter number of types of coins");
        int typeOfCoins = int.Parse(Console.ReadLine());
        SortedDictionary<int, int> coins = new SortedDictionary<int, int>();
        Console.WriteLine("Enter type of coin and its number separated by space");
        for (int count = 0; count < typeOfCoins; count++)
        {
            string input = Console.ReadLine();
            string[] inputData = input.Split(' ');
            coins.Add(int.Parse(inputData[0]), int.Parse(inputData[1]));
        }

        // Get each time from the bigger possible coin type
        // Till there are more coins and did not ecxeeded the amount
        Dictionary<int, int> used = new Dictionary<int, int>();
        while (coins.Count > 0 && amount > 0)
        {
            int maxType = coins.Keys.Max();
            int maxNumber = coins[maxType];
            used.Add(maxType, 0);
            while (coins[maxType] > 0 && amount >= maxType)
            {
                amount -= maxType;
                coins[maxType]--;
                used[maxType]++;
            }

            coins.Remove(maxType);
        }

        foreach (var item in used)
        {
            Console.WriteLine("{0} coin {1} times = {2}", item.Key, item.Value, item.Key * item.Value);
        }
    }
开发者ID:vasilkrvasilev,项目名称:DataStructuresAlgorithms,代码行数:39,代码来源:Coins.cs

示例15: CheckSignature

        //Check hash-sum
        public bool CheckSignature(Dictionary<string, string> formDictionary)
        {
            Int32 w1PaymentNo;
            SortedDictionary<string, string> sortedFormMd5Dictionary;
            StringBuilder strValues;
            string signature, message, tmpStr, decodedUrl;
            CodeUtils codeUtils;
            byte[] bytes, hash;

            sortedFormMd5Dictionary = new SortedDictionary<string, string>(
                formDictionary);
            w1PaymentNo = Convert.ToInt32(sortedFormMd5Dictionary["WMI_PAYMENT_NO"]);

            //сигнатура не нужна в вычислении
            sortedFormMd5Dictionary.Remove("WMI_SIGNATURE");
            codeUtils = new CodeUtils();

            strValues = new StringBuilder();
            foreach (var key in sortedFormMd5Dictionary.Keys)
            {
                //Очень, очень важно расшифровать строку (UrlDecode). Так как входные
                //данные пришли из формы с атрибутом
                //this.Request.ContentType = "application/x-www-form-urlencoded"
                //Даже несмотря на то, что входные данные в charset = UTF-8
                decodedUrl = HttpUtility.UrlDecode(sortedFormMd5Dictionary[key]);
                strValues.Append(decodedUrl);
            }
            //не забыли сделать конкатенацию секретного ключа
            message = strValues.ToString() + SpecialConstants.MERCHANT_KEY;
            //получили MD5-подпись всех(кроме signature) полей post-формы
            bytes = Encoding.GetEncoding(1251).GetBytes(message);
            hash = new MD5CryptoServiceProvider().ComputeHash(bytes);
            signature = Convert.ToBase64String(hash);

            if (signature == HttpUtility.UrlDecode(formDictionary["WMI_SIGNATURE"]))
                return true; //подписи совпали
            //либо отправитель злоумышленник, либо ошибка программиста
            else return false;
        }
开发者ID:blackknight16,项目名称:BookMarket,代码行数:40,代码来源:PaymentService.cs


注:本文中的SortedDictionary.Remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。