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


C# Set.AddMany方法代码示例

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


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

示例1: Main

    static void Main()
    {
        Console.WriteLine("Please enter in a single line a sequence of integers separated by an interval: ");
        string line = Console.ReadLine();
        string[] elements = line.Split(' ');

        List<int> seq = new List<int>();
        foreach (string el in elements)
        {
            seq.Add(int.Parse(el));
        }

        Set<int> set = new Set<int>();
        set.AddMany(seq);

        set.RemoveAll(setElement => (seq.FindAll(seqElement => seqElement == setElement).Count % 2 == 1));

        seq.RemoveAll(seqElement => !set.Contains(seqElement));

        Console.WriteLine("The new sequence with removed elements that occur odd number of times is: ");
        Console.WriteLine(String.Join(" ", seq));
    }
开发者ID:smihaylovit,项目名称:DSA,代码行数:22,代码来源:RemoveOddTimesOccurs.cs

示例2: MorphAndLookupToken

		/// <summary>
		/// Does the real work of morphing the specified word.
		/// </summary>
		/// <param name="word">The word.</param>
		/// <param name="prev">The previous word.</param>
		/// <param name="next">The next word.</param>
		/// <param name="trace">The trace.</param>
		/// <param name="selectTraceMorphs"></param>
		/// <returns>All valid word synthesis records.</returns>
		ICollection<WordSynthesis> MorphAndLookupToken(string word, string prev, string next, TraceManager trace, string[] selectTraceMorphs)
		{
			PhoneticShape input;
			try
			{
				// convert the word to its phonetic shape; it could throw a missing phonetic shape exception
				input = SurfaceStratum.CharacterDefinitionTable.ToPhoneticShape(word, ModeType.ANALYSIS);
			}
			catch (MissingPhoneticShapeException mpse)
			{
				var me = new MorphException(MorphException.MorphErrorType.INVALID_SHAPE, this,
					string.Format(HCStrings.kstidInvalidWord, word, SurfaceStratum.CharacterDefinitionTable.ID, mpse.Position+1,
									word.Substring(mpse.Position), mpse.PhonemesFoundSoFar));
				me.Data["shape"] = word;
				me.Data["charDefTable"] = SurfaceStratum.CharacterDefinitionTable.ID;
				me.Data["position"] = mpse.Position;
				me.Data["phonemesFoundSoFar"] = mpse.PhonemesFoundSoFar;
				throw me;
			}

			var inputAnalysis = new WordAnalysis(input, SurfaceStratum);

			if (trace != null)
				trace.BeginAnalyzeWord(word, inputAnalysis);

			var candidates = new Set<WordSynthesis>();
			var inAnalysis = new Set<WordAnalysis>();
			var outAnalysis = new Set<WordAnalysis>();
			inAnalysis.Add(inputAnalysis);

			// Unapply rules
			for (int i = m_strata.Count - 1; i >= 0; i--)
			{
				outAnalysis.Clear();
				foreach (WordAnalysis wa in inAnalysis)
				{
					if (trace != null)
						trace.BeginUnapplyStratum(m_strata[i], wa);

					foreach (WordAnalysis outWa in m_strata[i].Unapply(wa, trace, selectTraceMorphs, candidates))
					{
						// promote each analysis to the next stratum
						if (i != 0)
							outWa.Stratum = m_strata[i - 1];

						if (trace != null)
							trace.EndUnapplyStratum(m_strata[i], outWa);

						outAnalysis.Add(outWa);
					}
				}

				inAnalysis.Clear();
				inAnalysis.AddMany(outAnalysis);
			}

			var allValidSyntheses = new Set<WordSynthesis>();
			// Apply rules for each candidate entry
			foreach (WordSynthesis candidate in candidates)
			{
				var inSynthesis = new Set<WordSynthesis>();
				var outSynthesis = new Set<WordSynthesis>();
				for (int i = 0; i < m_strata.Count; i++)
				{
					// start applying at the stratum that this lex entry belongs to
					if (m_strata[i] == candidate.Root.Stratum)
						inSynthesis.Add(candidate);

					outSynthesis.Clear();
					foreach (WordSynthesis cur in inSynthesis)
					{
						if (trace != null)
							trace.BeginApplyStratum(m_strata[i], cur);

						foreach (WordSynthesis outWs in m_strata[i].Apply(cur, trace))
						{
							// promote the word synthesis to the next stratum
							if (i != m_strata.Count - 1)
								outWs.Stratum = m_strata[i + 1];

							if (trace != null)
								trace.EndApplyStratum(m_strata[i], outWs);

							outSynthesis.Add(outWs);
						}
					}

					inSynthesis.Clear();
					inSynthesis.AddMany(outSynthesis);
				}

//.........这里部分代码省略.........
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:101,代码来源:Morpher.cs

示例3: MorphAndLookupToken

		/// <summary>
		/// Does the real work of morphing the specified word.
		/// </summary>
		/// <param name="word">The word.</param>
		/// <param name="prev">The previous word.</param>
		/// <param name="next">The next word.</param>
		/// <param name="trace">The trace.</param>
		/// <returns>All valid word synthesis records.</returns>
		ICollection<WordSynthesis> MorphAndLookupToken(string word, string prev, string next, out WordAnalysisTrace trace)
		{
			// convert the word to its phonetic shape
			PhoneticShape input = SurfaceStratum.CharacterDefinitionTable.ToPhoneticShape(word, ModeType.ANALYSIS);
			// if word contains invalid segments, the char def table will return null
			if (input == null)
			{
				MorphException me = new MorphException(MorphException.MorphErrorType.INVALID_SHAPE, this,
					string.Format(HCStrings.kstidInvalidWord, word, SurfaceStratum.CharacterDefinitionTable.ID));
				me.Data["shape"] = word;
				me.Data["charDefTable"] = SurfaceStratum.CharacterDefinitionTable.ID;
				throw me;
			}

			// create the root of the trace tree
			trace = new WordAnalysisTrace(word, input.Clone());

			Set<WordSynthesis> candidates = new Set<WordSynthesis>();
			Set<WordAnalysis> inAnalysis = new Set<WordAnalysis>();
			Set<WordAnalysis> outAnalysis = new Set<WordAnalysis>();
			inAnalysis.Add(new WordAnalysis(input, SurfaceStratum, trace));

			// Unapply rules
			for (int i = m_strata.Count - 1; i >= 0; i--)
			{
				outAnalysis.Clear();
				foreach (WordAnalysis wa in inAnalysis)
				{
					if (m_traceStrataAnalysis)
					{
						// create the stratum analysis input trace record
						StratumAnalysisTrace stratumTrace = new StratumAnalysisTrace(m_strata[i], true, wa.Clone());
						wa.CurrentTrace.AddChild(stratumTrace);
					}
					foreach (WordAnalysis outWa in m_strata[i].Unapply(wa, candidates))
					{
						// promote each analysis to the next stratum
						if (i != 0)
							outWa.Stratum = m_strata[i - 1];

						if (m_traceStrataAnalysis)
							// create the stratum analysis output trace record for the output word synthesis
							outWa.CurrentTrace.AddChild(new StratumAnalysisTrace(m_strata[i], false, outWa.Clone()));

						outAnalysis.Add(outWa);
					}
				}

				inAnalysis.Clear();
				inAnalysis.AddMany(outAnalysis);
			}

			Set<WordSynthesis> allValidSyntheses = new Set<WordSynthesis>();
			// Apply rules for each candidate entry
			foreach (WordSynthesis candidate in candidates)
			{
				Set<WordSynthesis> inSynthesis = new Set<WordSynthesis>();
				Set<WordSynthesis> outSynthesis = new Set<WordSynthesis>();
				for (int i = 0; i < m_strata.Count; i++)
				{
					// start applying at the stratum that this lex entry belongs to
					if (m_strata[i] == candidate.Root.Stratum)
						inSynthesis.Add(candidate);

					outSynthesis.Clear();
					foreach (WordSynthesis cur in inSynthesis)
					{
						if (m_traceStrataSynthesis)
						{
							// create the stratum synthesis input trace record
							StratumSynthesisTrace stratumTrace = new StratumSynthesisTrace(m_strata[i], true, cur.Clone());
							cur.CurrentTrace.AddChild(stratumTrace);
						}
						foreach (WordSynthesis outWs in m_strata[i].Apply(cur))
						{
							// promote the word synthesis to the next stratum
							if (i != m_strata.Count - 1)
								outWs.Stratum = m_strata[i + 1];

							if (m_traceStrataSynthesis)
								// create the stratum synthesis output trace record for the output analysis
								outWs.CurrentTrace.AddChild(new StratumSynthesisTrace(m_strata[i], false, outWs.Clone()));

							outSynthesis.Add(outWs);
						}
					}

					inSynthesis.Clear();
					inSynthesis.AddMany(outSynthesis);
				}

				foreach (WordSynthesis ws in outSynthesis)
//.........这里部分代码省略.........
开发者ID:sillsdev,项目名称:WorldPad,代码行数:101,代码来源:Morpher.cs

示例4: Main

    static void Main()
    {
        Console.Write("Enter number of elements to read: ");
        string line = Console.ReadLine();
        int N;
        while (!(int.TryParse(line, out N) && N > 0))
        {
            Console.Write("Please enter a positive integer: ");
            line = Console.ReadLine();
        }
        Console.WriteLine();

        int[] numbers = new int[N];
        for (int idx = 0; idx < N; idx++)
        {
            Console.Write("Enter number {0}: ", idx + 1);
            line = Console.ReadLine();
            while (!(int.TryParse(line, out numbers[idx])))
            {
                Console.Write("Please enter an integer: ");
                line = Console.ReadLine();
            }
            Console.WriteLine();
        }

        Console.Write("{" + String.Join(", ", numbers) + "} -> ");

        int majMinOccurs = N / 2 + 1;

        /*Solution 1 - Predicates*/

        List<int> numbersList = numbers.ToList<int>();
        Set<int> numbersSet = new Set<int>();

        numbersSet.AddMany(numbersList);

        try
        {
            int majorant = numbersSet.First(setElement => (numbersList.FindAll(
                listElement => listElement == setElement).Count >= majMinOccurs));
            Console.WriteLine(majorant);
        }
        catch
        {
            Console.WriteLine("No majorant!");
        }

        Console.WriteLine();

        /*Solution 2 - Dictionary*/

        //Dictionary<int, int> occurrences = new Dictionary<int, int>();

        //for (int i = 0; i < N; i++)
        //{
        //    if (!occurrences.Keys.Contains(numbers[i]))
        //    {
        //        occurrences.Add(numbers[i], 1);
        //    }
        //    else
        //    {
        //        occurrences[numbers[i]]++;
        //    }
        //}

        //bool hasMajorant = false;

        //foreach (KeyValuePair<int, int> pair in occurrences)
        //{
        //    if (pair.Value >= majMinOccurs)
        //    {
        //        Console.WriteLine(pair.Key);
        //        hasMajorant = true;
        //        break;
        //    }
        //}

        //if (!hasMajorant)
        //{
        //    Console.WriteLine("No majorant!");
        //}

        //Console.WriteLine();
    }
开发者ID:smihaylovit,项目名称:DSA,代码行数:84,代码来源:FindMajorant.cs


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