Cycle, conditional
#include <the iostream> the using namespace STD; / * Function: count a specified number of times an integer appear in the pile integer idea: 1 to obtain data from the console to create a one-dimensional array 2, a length N, a memory obtained stack integer 3 to create a count variable 4 traverse the one-dimensional array, it is judged whether there had been an integer specified in the array, if present, the count variable is incremented. 1 * / int main () { COUT << " INPUT " << endl; // 5 / * initialize an array * / int NUM; CIN >> NUM; int height [NUM] = {}; // 85 78 90 99 60 / * processing digital string into an array of integer numbers */ char ch; if ((ch = getchar()) == '\n') { int n = 0; char c; while((c = getchar())!='\n') { if(c >= '0' && c <= '9') { ungetc(c,stdin); cin >> height[n++]; } } } int number; cin >> number; //cout << number << endl; int len = (int) sizeof(height) / sizeof(*height); int counter = 0; for(int i = 0;i < len;i++) { if(number == height[i]) counter++; } cout << "output" << endl; cout << counter << endl; return 0; }
Test Results: