我需要一些关于要求编写函数以查找出现次数最多/最少的偶数的作业的建议。
我的输出应如下所示:
How many integers (to be worked on) ? 2
Enter integer #1: 1230476
Enter integer #2: 10034850
Occurrence 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
Digit 9 : 0
Occurence of all existing EVEN digits --
Digit 0 : 4
Digit 2 : 1
Digit 4 : 2
Digit 6 : 1
Digit 8 : 1
出现次数最多的偶数位 - 0
并且出现次数:4
出现次数最少的偶数位 - 2 6 8 出现次数:1
到目前为止,这是我的代码......我似乎无法找到找到最大/最小事件的最后一部分..
到目前为止,这是我的代码: void displayDigitInfoUpdateStanDeng() {
int intsWorkedOn;
int* intValue;
int allDigitCount[10] = {0};
int largestOccurEven;
int smallestOccurEven;
int curDigit;
cout << "\n Calling on displayDigitInfoUpdateStanDeng() --"
<< "\n How many integers (to be worked on) ? ";
cin >> intsWorkedOn;
intValue = new int[intsWorkedOn];
for (int i = 0; i < intsWorkedOn; i++) {
cout << " Enter integer #" << i + 1 << ": ";
cin >> *(intValue + i);
}
for (int i = 0; i < intsWorkedOn; i++) {
do {
allDigitCount[*(intValue + i) % 10]++;
*(intValue + i) /= 10;
} while (*(intValue + i));
}
cout << "\n Occurence of all existing digits --";
for (int i = 0; i < 10; i++) {
cout << "\n Digit " << i << " : " << allDigitCount[i];
}
cout << "\n Occurence of all existing EVEN digits --";
for (int i = 0; i < 9; i++) {
cout << "\n Digit " << i - 1 << " : " << allDigitCount[i++];
}
cout << "\n The even digit(s) that has/have the largest occurrence -";
for (int i = 0; i < 9; i++) {
largestOccurEven = allDigitCount[i++] % 10;
curDigit = allDigitCount[i++];
if (curDigit < largestOccurEven) {
cout << "\n " << i
<< "\n And the number of occurrence(s) : " << largestOccurEven;
} else {
cout << endl;
}
}
这是我当前的输出:
有多少个整数(待处理)?2 输入整数#1:1230476 输入整数#2:10034850
Occurrence 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
Digit 9 : 0
Occurence of all existing EVEN digits --
Digit 0 : 4
Digit 2 : 1
Digit 4 : 2
Digit 6 : 1
Digit 8 : 1
出现次数最多的偶数位 - 2
并且出现次数:4
出现次数最少的偶数位 - ? 并且出现次数:0
我很困惑...为什么将 i 显示为 2 表示最大的出现次数?我真的需要帮助!