0

我正在努力使用我的代码来查找数组中出现的数字。如果用户提供 1230476 和 10034850 作为他们的两个整数,它应该表明对于偶数位,最大出现次数为 0 和出现次数为 4,最小出现次数为 2、6、8,只有 1 次出现。对于出现的次数,我没有得到正确的结果,这是我的输出:

How many integers (to be worked on)? 2
   Enter integer #1: 1230476
   Enter integer #2: 10034850

   Occurence of all existing digits --
     Digit 0 : 4
     Digit 1 : 2
     Digit 2 : 1
     Digit 3 : 2
     Digit 4 : 2
     Digit 5 : 1
     Digit 6 : 1
     Digit 7 : 1
     Digit 8 : 1

   Occurence of all existing EVEN digits --
     Digit 0 : 4
     Digit 2 : 1
     Digit 4 : 2
     Digit 6 : 1
     Digit 8 : 1

   The even digit(s) that has/have the largest occurrence -
     0
   And the number of occurrence(s) : 1

   The even digit(s) that has/have the smallest occurance -
     2
     6
     8
   And the number of occurence(s) : 1

   Occurence of all existing ODD digits --
     Digit 1 : 2
     Digit 3 : 2
     Digit 5 : 1
     Digit 7 : 1

   The odd digit(s) that has/have the largest occurrence -
   And the number of occurrence(s) : 1

   The odd digit(s) that has/have the smallest occurrence -
     5
     7
   And the number of occurrence(s) : 1

我的代码是:

  cout << "\n       The even digit(s) that has/have the largest occurrence -";
  for (i = 0; i < 10; i += 2) {
    mostOccuringEven = digitCount[i] % 10;

    if (digitCount[i] != 0) {
      if (mostOccuringEven > integersToWorkOn) {
        cout << "\n         " << i;
      }
    }
  }
  cout << "\n       And the number of occurrence(s) : " << mostOccuringEven;

这是我第一次发帖,如果我做的不对,请道歉......在这里感谢任何帮助!

4

0 回答 0