#include <iostream>
#include <vector>
// using namespace std; // *** avoid
/*void*/ int main() // *** main must return int
{
const int a[] = { 1, 2, 2, -2, 2, -2, 3, -2, 3, -3, -2 };
const int N = sizeof(a) / sizeof( a[0] ) ;
// find the smallest and biggest elements
int smallest = a[0] ;
int biggest = a[0] ;
for( int i = 1 ; i < N ; ++i )
{
if( a[i] < smallest ) smallest = a[i] ;
if( a[i] > biggest ) biggest = a[i] ;
}
// we can't use a c-style array for f; size is not known at compile time
// http://w...content-available-to-author-only...a.com/tutorials/vectors.html
std::vector<int> f( (biggest-smallest) + 1 ) ;
for( int i = 0 ; i < N ; ++i ) ++f[ a[i] - smallest ] ;
for( std::size_t i = 0 ; i < f.size() ; ++i )
{
const int count = f[i] ;
if( count > 0 )
{
const int n = i + smallest ;
std::cout << n << " appears " << count << " time" ;
if( count > 1 ) std::cout << 's' ;
std::cout << ".\n" ;
}
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgovLyB1c2luZyBuYW1lc3BhY2Ugc3RkOyAvLyAqKiogYXZvaWQKCi8qdm9pZCovIGludCBtYWluKCkgLy8gKioqIG1haW4gbXVzdCByZXR1cm4gaW50CnsKICAgIGNvbnN0IGludCBhW10gPSB7IDEsIDIsIDIsIC0yLCAyLCAtMiwgMywgLTIsIDMsIC0zLCAtMiB9OwogICAgY29uc3QgaW50IE4gPSBzaXplb2YoYSkgLyBzaXplb2YoIGFbMF0gKSA7CgogICAgLy8gZmluZCB0aGUgc21hbGxlc3QgYW5kIGJpZ2dlc3QgZWxlbWVudHMKICAgIGludCBzbWFsbGVzdCA9IGFbMF0gOwogICAgaW50IGJpZ2dlc3QgPSBhWzBdIDsKICAgIGZvciggaW50IGkgPSAxIDsgaSA8IE4gOyArK2kgKQogICAgewogICAgICAgIGlmKCBhW2ldIDwgc21hbGxlc3QgKSBzbWFsbGVzdCA9IGFbaV0gOwogICAgICAgIGlmKCBhW2ldID4gYmlnZ2VzdCApIGJpZ2dl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