Can any one help!

int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
	cin>>a[i];
int i=0,mn;
sort(a,a+n);
	mn=a[0];
set <int> s(a,a+n);
for(int aa:s)
	cout<<aa;
cout<<endl;
cout<<s.size()<<" size";

when input is
3
1 1 1
why it is not printing size of set???
can any one tell the mistake i have done??

It is printing the size (1) as in this case all elements are the same.

2 Likes

kindly change your ide, it works fine in My ide
its give me output as
1
1 size

A set can’t have copies of same element.

can suggest the good one??

multiset<int> s;

a is not variable it is name of array.
set s(a,a+n); <----- not possible

@gouthamreddy12 , your code is working fine , as you are using set , so it will not have any duplicate items.
For 111, you code is giving 1 as size of your set :slight_smile: