Untitled
unknown
c_cpp
3 years ago
865 B
8
Indexable
#include <iostream>
int main()
{
bool stop = false;
int n,temp,index = 0,count=1;
std::cin >> n; int a[n];
for (int i = 0; i < n; i++) std::cin >> a[i];
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (a[j] < a[i])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
while (stop == false)
{
for (int i=index+1;i<n;i++)
{
if (a[index] == a[i]) count ++;
else {
std::cout << a[index] << ':' << count << std::endl;
index = i;
break;
}
stop = true;
}
if (stop == true) std::cout << a[index] << ':' << count << std::endl;
count = 1;
}
}Editor is loading...