Help me with a code

Pages: 12
closed account (D80DSL3A)
Code restored on request:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//#include <map>
//#include <iostream>

int main() {
    std::map<int, unsigned int> numberCount;

    int x;
    while (std::cin >> x ) {
        ++numberCount[x];
    }

    std::cout << "x\tcount\n";
    // OK. I see how a range based for loop would be nice here. I should update my compiler.
    for ( std::map<int, unsigned int>::const_iterator it = numberCount.begin(); it != numberCount.end(); ++it )
        std::cout << it->first << '\t' << it->second << '\n';

    return 0;
}

The code is adapted from this post in another thread:
http://www.cplusplus.com/forum/beginner/132369/#msg712641
Last edited on
hey man.
its worked.(in 0.632 sec)
just delete temparry.
new code is here.
But we can steel make it Better, do you want it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace std;

void Bublesort(int array[] , int n)
{
	for(int i = 0 ; i < n - 1 ; i++)
		for( int j = 0 ; j < n - i - 1 ; j++)
			if(array[j] > array[j+1])
			{
				int temp = array[j];
				array[j] = array[j+1];
				array[j+1] = temp;
			}
}

int main()
{
	int N;
	cin>>N;
	int *arry = new int [N];
	for(int i = 0; i < N; i++)
		cin>>arry[i];
	Bublesort(arry , N);
		int ii = 1;
		for(int i = 0 ; i < N ; i++)
		{
			if(arry[i] == arry[i+1])
				ii++;
			else
			{
				cout<<arry[i]<<" aparece "<<ii<<" vez(es)"<<endl;
				ii = 1;
			}

		}
}
Thaaaaanks Amirtork :)
the last code worked thx you very mutch bro <3
Topic archived. No new replies allowed.
Pages: 12