During the two courses at the university, I realized that I could not program a damn thing. Now I want to solve this problem. To begin with, I think I need to figure out what I need to repeat. Algorithmic thinking is lame and knowledge of the language is lame. Here I am posting the puzzle I was trying to solve. Find the number of different elements in the array. Problems solved not correctly, but so far I can not figure out how to solve. With this task, I want to identify my gaps and get recommendations on how to eliminate them. Thanks in advance.
#include <iostream> using namespace std; int main() { const int size = 10; int arr[size] = { 10, 1, 1, 3, 1, 3, 1, 8, 9, 2 }; int count = 0; for (int i = 0; i < size; ++i) { for (int j = size - 1; j > i; --j) { if (arr[i] != arr[j]) { count++; break; } else --j; } } cout << count << endl; return 0; }