Finding a minimum number of repeats



  • I've got a code to find just the numbers of the same numbers in active textboxes on the button application and the withdrawal of this number in. label2: C#

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (TextBox tb in Controls.OfType<TextBox>().Where(x => x.Enabled == true))
            {
                label2.Text = Controls.OfType<TextBox>().SelectMany(x => x.Text.Split(" ;:,.-".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)).GroupBy(x => x).Count(x => x.Count() > 1).ToString();
            }
        }
    

    Tell me how to redo this code so that it compares not all active textboxes at once, but everyone with others, like the first one with the second, the first one with the third, and so on, then goes back to the second and compares it to the next, and so on. That's the first. The second is that the code, after comparing the textboxes with each other, should make a minimum number of the same numbers possible in the label. 0I mean, even if there's no match at all. And I would like to see, after all, which textboxes have found a minimum repetitive numbers, such as changing their background colours.BackColorTo others.

    A little explanation for all this. In the code tb - it's a bunch of textboxes. Each tekbox has different numbers and does not repeat, they are introduced by the user, not at home, and through a gap. And to be clear, I'll give you a simple example with three textboxes. Number one. 10 15 2010 11 2530 11 25♪ It shows that the first one with the second one match, the second with the third two, the first one with the third one. As a result of the mines, the same numbers 0and this number is inserted into the label, and the textboxes first and third change their background colour.

    Yeah, and if it's not hard, how am I supposed to make another button comparing textboxes not everyone but just the first one with all the others? For example, if textbox 3 compares the first to the second and to the third, and no second to third. And again, after all this, make a minimum and change the colors of the backgrounds. Thank you very much.



  • I'll give you an example on whole numbers. How to get them and the lines. TextBox.Text You already have an example in the code.

    Let's say we have a list of masses. List<int[]> arrays;

    Tell me how to redo this code so it doesn't compare everything. active textboxes at once, and each with, for example, the first with Second, first, third, then returned to second and second. Compared it to the next, and so on.

    a simple overbearing algorithm.

    var min = a.Max(p => p.Length) + 1;
    var index1 = -1;
    var index2 = -1;
    

    for(int i = 0; i < arrays.Count - 1; i++)
    for (int j = i+1; j < arrays.Count; j++)
    {
    var t = arrays[i].Intersect(arrays[j]);
    if(min > t)
    {
    min = t;
    index1 = i;
    index2 = j;
    }
    }

    at the outlet, they receive a minimum of possible intersections and two sets of masses giving this minimum intersection. The complexity of O(N^3) with the search for intersections.

    I don't know what to do to compute another button.
    The textboxes aren't everyone, but just the first one with everyone else?

    Also, in lieu of an external cycle in which it changes i - record its value on the right index and start with j = 0♪ Complexity of O(N^2), taking into account the search for intersections.

    I need the code, after comparing textboxes with each other,
    Label text (aybe) minimum number of the same
    chisel, maybe even 0, that's even if there's no match. And
    I'd like to see if there's anything in it after all.
    The textboxes found a minimum repetitive numbers, for example
    Change their background colors to others.

    Now you know the meaning of the minimum that's left to just fit in. Labeland the mass indexes of the right couple.
    If the volume indices correspond to the indices TextBox-Oh, it's not hard to use the cycle from your example, so we know the indices. TextBox- that needs to be painted.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2