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


C# SortedDictionary.ElementAt方法代码示例

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


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

示例1: cycle_check

        public string cycle_check(SortedDictionary<char, char> cycle)
        {
            cycle_str = "A";
            cycle_key = 'A';
            cycle_value = cycle['A'];
            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,代码来源:Data.cs

示例2: TextureManager

        public TextureManager(ContentManager Content)
        {
            _texturesTerrain = Helpers.LoadContent<Texture2D>(Content, "terrain");
            _texturesTerrainMasks = Helpers.LoadContent<Texture2D>(Content, "terrain-masks");
            _priorityTerrain = new SortedDictionary<string, int>();

            for (int i = 0; i < _texturesTerrain.Count; i++)
            {
                _texturesTerrain.ElementAt(i).Value.Name = _texturesTerrain.ElementAt(i).Key;
                //TODO: Priorität implementieren!!!
                _priorityTerrain.Add(_texturesTerrain.ElementAt(i).Key, new Random().Next(0,_texturesTerrain.Count));
            }
            for (int i = 0; i < _texturesTerrainMasks.Count; i++)
            {
                _texturesTerrainMasks.ElementAt(i).Value.Name = _texturesTerrainMasks.ElementAt(i).Key;
            }
        }
开发者ID:CommanderWayan,项目名称:HexaTest,代码行数:17,代码来源:TextureManager.cs

示例3: searchBox_QuerySubmitted

        async void searchBox_QuerySubmitted(string querytext)
        {
            string massive_text = String.Empty;
            SBSearchStep1.Begin();
            SBSearchStep1.Completed += (_, __) =>
            {
                this.Results.Clear();
                this.Answer = String.Empty;
            };

            // Get a JsonArray of paraphrased sentences
            var paraphrases = await SNCT.Rephrasing.GetParaphrases(querytext, 5);
            //await System.Threading.Tasks.Task.Delay(1000);
            SBSearchStep2.Begin();
            var paraphrases_list = new List<string>();
            foreach (var query in paraphrases)
            {
                // get the string from the JsonArray
                string q = query.GetString();
                paraphrases_list.Add(q);
                // Grab the first result (to be changed)
                this.Results.Add((await SNCT.BingProvider.GetResultsForQuery(q))[0]);
            }
            SBSearchStep3.Begin();
            for (var i = 0; i < this.Results.Count; i++)
            {
                // Add the extracted text to our giant blob
                massive_text += await SNCT.AlchemyProvider.URLGetText(this.Results[i].Url);
            }
            SBSearchStep4.Begin();
            // get an string answer from Sam's stuff :)
            var answer = await Finder.answer(massive_text, paraphrases_list.ToArray(), 5);
            // get the ordereddict to sort these for us--it sorts by increasing Key (aka the sentence score [double])
            var ordered_answers = new SortedDictionary<double, string>();
            foreach (var a in answer)
            {
                // we actually want the higher scores to be first, so lets fudge it instead of writing our own comparator
                ordered_answers.Add(100.0 - a.Value, a.Key);
            }

            this.Answer = ordered_answers.ElementAt(0).Value + "\n\n" + ordered_answers.ElementAt(1).Value;

            this.DataContext = this.Answer;
            ShowResultsStoryboard.Begin();
        }
开发者ID:samueltenka,项目名称:SNCT,代码行数:45,代码来源:MainPage.xaml.cs

示例4: Playfield

        public Playfield(int Height, int Width, ContentManager Content)
        {
            this._height = Height;
            this._width = Width;
            this._playfield = new Hexfield[_height, _width];
            this._content = Content;
            this._texMan = new TextureManager(Content);
            this._textures = _texMan.TexturesTerrain;
            this._texturesMasks = _texMan.TexturesTerrainMasks;

            int counter = 0;
            Random rnd = new Random();

            for (int y = 0; y <= _playfield.GetUpperBound(0); y++)
            {
                for (int x = 0; x <= _playfield.GetUpperBound(1); x++, counter++)
                {
                    int rnTexElement = rnd.Next(0, _textures.Count);
                    int tnMaskElement = rnd.Next(0, _texturesMasks.Count);
                    int prioTemp = _texMan.PriorityTerrain[_textures.ElementAt(rnTexElement).Key];
                    if ((x % 2) == 0) // gerade
                    {
                        _playfield[y, x] = new Hexfield(new Point((int)((Help.Helpers.HexFieldWidth) * (3.0/4.0)) * x,
                                                                 (Help.Helpers.HexFieldHeight) * y),
                                                                  counter,
                                                                  _textures.ElementAt(rnTexElement).Value,
                                                                  _texturesMasks.ElementAt(tnMaskElement).Value,
                                                                  x,y, prioTemp);
                    }
                    else
                    {
                        _playfield[y, x] = new Hexfield(new Point((int)((Help.Helpers.HexFieldWidth) * (3.0/4.0)) * x,
                                                                 (Help.Helpers.HexFieldHeight * y + Help.Helpers.HexFieldHeight / 2)),
                                                                  counter,
                                                                  _textures.ElementAt(rnTexElement).Value,
                                                                  _texturesMasks.ElementAt(tnMaskElement).Value,
                                                                  x,y, prioTemp);
                    }
                }
            }
            setHexEdgeTextures();
            //blendNeighbors();
        }
开发者ID:CommanderWayan,项目名称:HexaTest,代码行数:43,代码来源:playfield.cs

示例5: Main

        public static void Main()
        {
            StreamReader reader = new StreamReader(@"../../students.txt");
            using (reader)
            {
                SortedDictionary<string, List<Student>> courses = new SortedDictionary<string, List<Student>>();
                while (true)
                {
                    var line = reader.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    var data = line.Split(new char[] { '|', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    Student student = new Student(data[0], data[1]);
                    if (courses.ContainsKey(data[2]))
                    {
                        List<Student> studentsInCourse = courses[data[2]];
                        studentsInCourse.Add(student);
                        courses[data[2]] = studentsInCourse;
                    }
                    else
                    {
                        courses.Add(data[2], new List<Student>() { student });
                    }
                }

                for (int i = 0; i < courses.Count; i++)
                {
                    List<Student> studentsInCourse = courses.ElementAt(i).Value;
                    var key = courses.ElementAt(i).Key;
                    studentsInCourse = studentsInCourse.OrderBy(st => st.LastName).ThenBy(st => st.FirstName).ToList();
                    courses[key] = studentsInCourse;
                    Console.Write(courses.ElementAt(i).Key + ": " + string.Join(", ", courses.ElementAt(i).Value));
                    Console.WriteLine();
                }
            }
        }
开发者ID:emilti,项目名称:Telerik-Academy-My-Courses,代码行数:39,代码来源:MainProgram.cs

示例6: BookStats

        public BookStats(string path)
        {
            words = new SortedDictionary<string, int>();
            string text = File.ReadAllText(path);

            char[] delimiters = { ' ', '\n' };
            string[] allWords = text.Split(delimiters);

            foreach (string word in allWords)
            {
                if (words.ContainsKey(word))
                {
                    words[word]++;
                }
                else
                {
                    words.Add(word, 1);
                }
            }

            // POSTPROCESSING
            double avgFrequency = 0;
            int maxFrequency = 0;

            int freq;
            for (int i = 0; i < words.Count; i++)
            {
                freq = words.ElementAt(i).Value;
                avgFrequency += freq;
                if (freq > maxFrequency) maxFrequency = freq;
            }

            avgFrequency /= words.Count;

            Console.Write(
                "\n-----------------------------------\n" +
                "Filename: {0}\n" +
                "Unique Words: {1}\n" +
                "Average Frequency: {2}\n" +
                "Max Frequency: {3}\n" +
                "-----------------------------------\n\n",
                path,
                words.Count,
                avgFrequency,
                maxFrequency
            );
        }
开发者ID:marcbizal,项目名称:CPT244,代码行数:47,代码来源:Program.cs

示例7: Write_ItemNavForm_Closing

        /// <summary> This is an opportunity to write HTML directly into the main form, without
        /// using the pop-up html form architecture </summary>
        /// <param name="Output"> Textwriter to write the pop-up form HTML for this viewer </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <remarks> This text will appear within the ItemNavForm form tags </remarks>
        public override void Write_ItemNavForm_Closing(TextWriter Output, Custom_Tracer Tracer)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("File_Management_MySobekViewer.Write_ItemNavForm_Closing", "");
            }

            // Add the hidden fields first
            Output.WriteLine("<!-- Hidden field is used for postbacks to indicate what to save and reset -->");
            Output.WriteLine("<input type=\"hidden\" id=\"action\" name=\"action\" value=\"\" />");
            Output.WriteLine("<input type=\"hidden\" id=\"phase\" name=\"phase\" value=\"\" />");
            Output.WriteLine("<script type=\"text/javascript\" src=\"" + Static_Resources.Sobekcm_Metadata_Js + "\" ></script>");

            Output.WriteLine("<hr />");
            Output.WriteLine("<br />");

            // Any download files?
            string[] files = Directory.GetFiles(digitalResourceDirectory);
            if (files.Length > 0)
            {
                Output.WriteLine("The following new page images will be added to the item once you click SUBMIT:");
                Output.WriteLine("<table class=\"sbkMySobek_FileTable\">");
                Output.WriteLine("  <tr style=\"min-height:22px;\" >");
                Output.WriteLine("    <th style=\"width:350px;\">FILENAME</th>");
                Output.WriteLine("    <th style=\"width:90px\">SIZE</th>");
                Output.WriteLine("    <th style=\"width:170px\">DATE UPLOADED</th>");
                Output.WriteLine("    <th style=\"width:90px; text-align: center;\">ACTION</th>");
                Output.WriteLine("  </tr>");

                // Collect the page files we are uploading into groups
                SortedDictionary<string, List<string>> file_groups = new SortedDictionary<string, List<string>>();
                foreach (string thisFile in files)
                {
                    FileInfo newFileInfo = new FileInfo(thisFile);
                    string name = newFileInfo.Name;
                    string extension = newFileInfo.Extension;
                    string name_sans_extension = name.Replace(extension, "").ToUpper();
                    if (name.ToUpper().IndexOf("THM.JPG") > 0)
                    {
                        name_sans_extension = name.ToUpper().Replace("THM.JPG","");
                    }

                    if ( file_groups.ContainsKey(name_sans_extension))
                        file_groups[name_sans_extension].Add(thisFile);
                    else
                    {
                        List<string> newGroup = new List<string> {thisFile};
                        file_groups.Add(name_sans_extension, newGroup);
                    }
                }

                // Step through all the page image file groups
                for (int i = 0; i < file_groups.Count; i++)
                {
                    List<string> groupFiles = file_groups.ElementAt(i).Value;

                    foreach (string thisFile in groupFiles)
                    {
                        // Add the file name literal
                        FileInfo fileInfo = new FileInfo(thisFile);
                        Output.WriteLine("  <tr style=\"min-height:22px;\">");
                        Output.WriteLine("    <td>" + fileInfo.Name + "</td>");
                        if (fileInfo.Length < 1024)
                            Output.WriteLine("    <td>" + fileInfo.Length + "</td>");
                        else
                        {
                            if (fileInfo.Length < (1024*1024))
                                Output.WriteLine("    <td>" + (fileInfo.Length/1024) + " KB</td>");
                            else
                                Output.WriteLine("    <td>" + (fileInfo.Length/(1024*1024)) + " MB</td>");
                        }

                        Output.WriteLine("    <td>" + fileInfo.LastWriteTime + "</td>");

                        //add by Keven:replace single & double quote with ascII characters
                        string strFileName = fileInfo.Name;
                        if (strFileName.Contains("'") || strFileName.Contains("\""))
                        {
                            strFileName = strFileName.Replace("'", "\\&#39;");
                            strFileName = strFileName.Replace("\"", "\\&#34;");
                        }
                        Output.WriteLine("    <td align=\"center\"> <span class=\"sbkMySobek_ActionLink\">( <a href=\"\" onclick=\"return file_delete('" + strFileName + "');\">delete</a> )</span></td>");

                        Output.WriteLine("  </tr>");
                    }
                    Output.WriteLine("  <tr><td class=\"sbkMySobek_FileTableRule\" colspan=\"4\"></td></tr>");
                }
                Output.WriteLine("</table>");
                Output.WriteLine();
            }

            Output.WriteLine("<div class=\"sbkMySobek_FileRightButtons\">");
            Output.WriteLine("  <button title=\"Cancel this and remove the recentely uploaded images\" onclick=\"return new_upload_next_phase(2);\" class=\"sbkPiu_RoundButton\">CANCEL</button> &nbsp; ");
            Output.WriteLine("  <button title=\"Submit the recently uploaded page images and complete the process\" onclick=\"return new_upload_next_phase(9);\" class=\"sbkPiu_RoundButton\">SUBMIT</button> &nbsp; ");
            Output.WriteLine("  <div id=\"circular_progress\" name=\"circular_progress\" class=\"hidden_progress\">&nbsp;</div>");
//.........这里部分代码省略.........
开发者ID:Elkolt,项目名称:SobekCM-Web-Application,代码行数:101,代码来源:Page_Image_Upload_MySobekViewer.cs

示例8: ShuffleInputs

		/// <summary>
		/// Insert the items in the input into the sorter in a mixed-up order.
		/// </summary>
		/// <param name="sorter"></param>
		/// <param name="input"></param>
		private void ShuffleInputs(BigDataSorter sorter, SortedDictionary<string, byte[]> input)
		{
			// Insert all the even items in oder.
			for (int i = 0; i < input.Count/2; i++)
			{
				sorter.Add(input.ElementAt(i * 2).Key, input.ElementAt(i * 2).Value);
			}
			// And all the odd items in reverse order.
			for (int i =  input.Count - 1; i > 0; i--)
			{
				if (i%2 == 1)
					sorter.Add(input.ElementAt(i).Key, input.ElementAt(i).Value);
			}
		}
开发者ID:sillsdev,项目名称:FieldWorks,代码行数:19,代码来源:TestBigSorting.cs

示例9: VerifyOutput

		private void VerifyOutput(List<byte[]> output, SortedDictionary<string, byte[]> input)
		{
			Assert.That(output.Count, Is.EqualTo(input.Count));
			for (int i = 0; i < input.Count; i++)
				VerifyByteArray(output[i], input.ElementAt(i).Value);
		}
开发者ID:sillsdev,项目名称:FieldWorks,代码行数:6,代码来源:TestBigSorting.cs

示例10: BuildRMatrix

        private void BuildRMatrix(double[] rDiag, int x, int y)
        {
            int c = rDiag.Length; // c = num classes
            for (int i = 0; i < c; ++i)
            {
                r[x, y, i, i] = rDiag[i];
            }
            // Sort the c classes into priority groups P with decreasing Ri
            List<Tuple<double, List<int>>> priorityGroups = new List<Tuple<double, List<int>>>();
            for (int i = 0; i < c; ++i)
            {
                bool found = false;
                List<Tuple<double, List<int>>>.Enumerator e = priorityGroups.GetEnumerator();
                while (e.MoveNext())
                {
                    if (e.Current.Item1 == rDiag[i])
                    {
                        e.Current.Item2.Add(i);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    List<int> classList = new List<int>();
                    classList.Add(i);
                    Tuple<double, List<int>> pi = new Tuple<double, List<int>>(rDiag[i], classList);
                    priorityGroups.Add(pi);
                }
            }
            SortedDictionary<double, List<int>> P = new SortedDictionary<double, List<int>>();
            {
                List<Tuple<double, List<int>>>.Enumerator e = priorityGroups.GetEnumerator();
                while (e.MoveNext())
                {
                    P.Add(-e.Current.Item1, e.Current.Item2); // negate the r key to reverse the sorting
                }
            }

            HashSet<int> C = new HashSet<int>();
            double D = 0;
            for (int k = 0; k < P.Count; ++k)
            {
                List<int> Pk = P.ElementAt(k).Value;
                foreach (int c_i in Pk)
                {
                    C.Add(c_i);
                    D += 1.0 / (rDiag[c_i] * rDiag[c_i]);
                }

                foreach (int c_i in Pk)
                {
                    foreach (int c_j in C)
                    {
                        if (c_i != c_j)
                        {
                            r[x, y, c_i, c_j] = r[x, y, c_j, c_i] = 1.0 / Math.Sqrt(D);
                        }
                    }
                }
            }
        }
开发者ID:joesfer,项目名称:ColorStippling,代码行数:63,代码来源:HardDiskSampling.cs

示例11: FindBestServer

 int FindBestServer(SortedDictionary<int, List<IDataLoader>> srvAv)
 {
     var pair = srvAv.ElementAt(0);
     for (int i = srvAv.Count - 1; i > 0; i--)
         if (pair.Value.Count > srvAv.Values.ElementAt(i).Count)
             pair = srvAv.ElementAt(i);
     return pair.Key;
 }
开发者ID:xCMNx,项目名称:BooruViewer.Net,代码行数:8,代码来源:DownloadManager.cs

示例12: SuggestNGrams

        // suggest N-Grams for a given array of input terms
        private static SortedDictionary<long, string[]> SuggestNGrams(string[] inputTerms)
        {
            int N = inputTerms.Length;

            SortedDictionary<long, string[]> suggestedNGrams = new SortedDictionary<long, string[]>();

            // Try N = N grams

            // only can suggest for N = 2+
            if (N > 1)
            {
                // try to get the subGram
                Dictionary<string, long> subGram = TryGetSubGramN(inputTerms, N);
                if (subGram != null)
                {
                    // suggest highest N-gram with
                    // first N-1 terms the same as the the first N-1 terms in the N-gram

                    // get top 5 scores
                    // XXX: might want to change to over some threshold on top of maximum of 5
                    // XXX: also should use edit distance in the formulation of weighting

                    long originalNGramScore = 0;
                    if (subGram.ContainsKey(inputTerms[N - 1]))
                    {
                        originalNGramScore = subGram[inputTerms[N - 1]];
                    }

                    long currentNGramScore = 0;
                    string suggestedLastTerm = "";
                    foreach (KeyValuePair<string, long> kvp in subGram)
                    {
                        currentNGramScore = kvp.Value;
                        suggestedLastTerm = kvp.Key;
                        // get the lowest score or 0 if nothing in the suggestions
                        long lowestScore = 0;
                        if (suggestedNGrams.Count > 0)
                        {
                            lowestScore = suggestedNGrams.ElementAt(0).Key;
                        }

                        // add if there aren't enough suggestions
                        if (suggestedNGrams.Count < 5 &&
                            currentNGramScore > originalNGramScore)
                        {
                            // add to the set
                            string[] suggestedTerms = new string[N + 1];
                            int i = 0;
                            for (; i < N - 1; i++)
                            {
                                suggestedTerms[i] = inputTerms[i];
                            }
                            suggestedTerms[N - 1] = suggestedLastTerm;
                            suggestedTerms[N] = currentNGramScore.ToString();

                            suggestedNGrams.Add(currentNGramScore, suggestedTerms);
                        }
                        // add the score if its high enough
                        else if (kvp.Value > lowestScore)
                        {
                            // remove the lowest scoring N Gram (top 5 for now)
                            if (suggestedNGrams.Count >= 5)
                            {
                                suggestedNGrams.Remove(lowestScore);
                            }

                            // add to the set
                            string[] suggestedTerms = new string[N + 1];
                            int i = 0;
                            for (; i < N - 1; i++)
                            {
                                suggestedTerms[i] = inputTerms[i];
                            }
                            suggestedTerms[N - 1] = suggestedLastTerm;
                            suggestedTerms[N] = currentNGramScore.ToString();

                            suggestedNGrams.Add(currentNGramScore, suggestedTerms);
                        }
                    }
                }
            }

            // Try to suggest N+1 grams
            if (N < 4)
            {
                // try to get the subGram
                Dictionary<string, long> subGram = TryGetSubGramN(inputTerms, N + 1);
                if (subGram != null)
                {
                    // suggest highest N+1-gram with
                    // first N terms the same as the the first N term in the N-gram

                    // get top 5 scores
                    // XXX: might want to change to over some threshold on top of maximum of 5
                    // XXX: also should use edit distance in the formulation of weighting

                    long currentNGramScore = 0;
                    string suggestedLastTerm = "";
                    foreach (KeyValuePair<string, long> kvp in subGram)
//.........这里部分代码省略.........
开发者ID:o0111,项目名称:ruralcafe,代码行数:101,代码来源:NGrams.cs

示例13: getHistory

        /// <summary>
        /// create a fake history for each customer this is a little convoluted to create all the fake data
        /// </summary>
        /// <returns></returns>
        private SortedDictionary<DateTime, Trasaction> getHistory()
        {
            SortedDictionary<DateTime, Trasaction> transactionHistory = new SortedDictionary<DateTime, Trasaction>();

            // create a pseudo transaction history
            while(transactionHistory.Count < 10)
            {
                Random random = new Random();
                decimal startingAmmount = random.Next(10000, 150000);
                int year = random.Next(1980, 2015);
                int month = random.Next(1, 12);
                int day = random.Next(1, 28);
                DateTime date = new DateTime(year,month,day);
                int transType = random.Next(1, 4);
                int ammount = random.Next(1, 5000);

                if(!transactionHistory.ContainsKey(date))
                {
                    transactionHistory.Add(date, new Trasaction(startingAmmount, ammount, (TransactionType)transType, Currency.USD));
                }
            }

            // clean up transactions so that they calculate correctly
            for(int i = 0; i < 10; i++)
            {
                if(i > 0)
                {
                    decimal oldBalance = transactionHistory.ElementAt(i - 1).Value.GetBalance();
                    decimal difference = transactionHistory.ElementAt(i).Value.GetAmmount();

                    if(transactionHistory.ElementAt(i).Value.GetTransactionType() == TransactionType.Deposit ||
                        transactionHistory.ElementAt(i).Value.GetTransactionType() == TransactionType.RecieveFromAccount)
                    {
                        transactionHistory.ElementAt(i).Value.SetBalance(oldBalance + difference);
                    }
                    else
                    {
                        transactionHistory.ElementAt(i).Value.SetBalance(oldBalance - difference);
                    }
                }
            }

            return transactionHistory;
        }
开发者ID:alexcompton,项目名称:BankConsole,代码行数:48,代码来源:Database.cs

示例14: Clear_Pagination_And_Reorder_Pages

        /// <summary>
        /// Clears all the page labels, division types and names, and reorders the pages by filename
        /// </summary>
        private void Clear_Pagination_And_Reorder_Pages()
        {
            SortedDictionary<string, Page_TreeNode> nodeToFilename = new SortedDictionary<string, Page_TreeNode>();
            int newPageCount = 0;

            // Add each page node to a sorted list/dictionary and clear the label
            foreach (Page_TreeNode thisNode in qc_item.Divisions.Physical_Tree.Pages_PreOrder)
            {
                thisNode.Label = String.Empty;
                string file_sans = "missing" + newPageCount;
                if (( thisNode.Files != null ) && ( thisNode.Files.Count > 0 ))
                    file_sans = thisNode.Files[0].File_Name_Sans_Extension;
                if (!nodeToFilename.ContainsKey(file_sans))
                {
                    nodeToFilename[file_sans] = thisNode;
                    newPageCount++;
                }

            }

            // Clear the physical (TOC) tree
            qc_item.Divisions.Physical_Tree.Clear();

            // Add the main node to the physical (TOC) division tree
            Division_TreeNode mainNode = new Division_TreeNode("Main", String.Empty);
            qc_item.Divisions.Physical_Tree.Roots.Add(mainNode);

            //Update the web Page count for this item
            qc_item.Web.Clear_Pages_By_Sequence();

            // Add back each page, in order by filename (sans extension)
            for (int i = 0; i < nodeToFilename.Count; i++)
            {
                mainNode.Add_Child(nodeToFilename.ElementAt(i).Value);
                qc_item.Web.Add_Pages_By_Sequence(nodeToFilename.ElementAt(i).Value);
            }

            //Update the QC web page count as well
            qc_item.Web.Static_PageCount = newPageCount;

            // Save the updated item to the session
            HttpContext.Current.Session[qc_item.BibID + "_" + qc_item.VID + " QC Work"] = qc_item;

            // Save to the temporary QC work section
            try
            {
                // Ensure the directory exists under the user's temporary mySobek InProcess folder
                if (!Directory.Exists(userInProcessDirectory))
                    Directory.CreateDirectory(userInProcessDirectory);

                // Save the METS
                qc_item.Save_METS(metsInProcessFile);
            }
            catch (Exception)
            {
                throw;
            }
        }
开发者ID:MarkVSullivan,项目名称:SobekCM-Web-Application,代码行数:61,代码来源:QC_ItemViewer.cs

示例15: Main

    static void Main()
    {
        SortedDictionary<byte, byte> cards = new SortedDictionary<byte, byte>();
        bool hasStraightPotential = true;
        byte aceCount = 0;

        for (int i = 0; i < 5; i++)
        {
            byte number = 0;
            string card = Console.ReadLine();

            switch (card)
            {
                case "J": number = 11; break;
                case "Q": number = 12; break;
                case "K": number = 13; break;
                case "A": number = 14; break;
                default: number = byte.Parse(card); break;
            }

            if (!cards.ContainsKey(number))
            {
                cards.Add(number, 1);
            }
            else
            {
                cards[number]++;

                // Once discovered key with value 2, the bool variable takes value FALSE
                hasStraightPotential = false;
            }
        }

        // We have 5 different cards -> Potential for straingth
        if (hasStraightPotential) 
        {
            if (cards.ContainsKey(14) && cards.ContainsKey(2))
            {
                // Potential for straight starting with A...2...
                aceCount = cards[14];
                cards.Add(1, 1);
                cards.Remove(14);
            }

            // Check if elements are consecutive 
            for (int i = 0; i < cards.Count - 1; i++)
            {
                if (cards.ElementAt(i).Key != cards.ElementAt(i + 1).Key - 1)
                {
                    hasStraightPotential = false;
                    break;
                }
            }

            if (hasStraightPotential)
            {
                Console.WriteLine("Straight");
                return;
            }
            else if (cards.ContainsKey(1))
            {
                cards.Add(14, aceCount);
                cards.Remove(1);
            }
        }

        if (cards.ContainsValue(5))
        {
            Console.WriteLine("Impossible"); return;
        }
        else if (cards.ContainsValue(4))
        {
            Console.WriteLine("Four of a Kind"); return;
        }
        else if (cards.ContainsValue(3) && cards.ContainsValue(2))
        {
            Console.WriteLine("Full House"); return;
        }
        else if (cards.ContainsValue(3) && !cards.ContainsValue(2))
        {
            Console.WriteLine("Three of a Kind"); return;
        }

        var sortedDict = (from entry in cards
                          orderby entry.Value descending
                          select entry).ToDictionary(pair => pair.Key, pair => pair.Value);

        if (sortedDict.ElementAt(0).Value == 2 && sortedDict.ElementAt(1).Value == 2)
        {
            Console.WriteLine("Two Pairs");
        }
        else if (sortedDict.ElementAt(0).Value == 2 && sortedDict.ElementAt(1).Value == 1)
        {
            Console.WriteLine("One Pair");
        }
        else
        {
            Console.WriteLine("Nothing");
        }
    }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:100,代码来源:3.+Poker+(Dictionary).cs


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