|
Ustivor navbat o‘rtasidagi element o‘chirib tashlansin. Agar navbat elementlari soni toq bo‘lsa, bitta element, aks holda ikkita element o‘chirilsin
|
Sana | 23.12.2022 | Hajmi | 36,82 Kb. | | #895072 |
| Bog'liq Ustivor navbat o‘rtasidagi element o‘chirib tashlansin. Agar nav
21
|
Ustivor_navbat o‘rtasidagi element o‘chirib tashlansin. Agar navbat elementlari soni toq bo‘lsa, bitta element, aks holda ikkita element o‘chirilsin.
|
#include
#include
using namespace std;
int main()
{
priority_queue sons,tuplam;
int n;
cout<<"N=";cin>>n;
for(int i=0;i
int son; cin>>son;
sons.push(son);
}
int urts=(sons.size())-(sons.size()/2);
int ulcham=sons.size();
for(int i=1;(i<=ulcham) && !sons.empty() ; i++)
if (urts==i && ulcham%2!=0) {
sons.pop();
} else if( (urts==i || (urts+1)==i ) && ulcham%2==0)
sons.pop();
else {
tuplam.push(sons.top());
sons.pop();
}
cout<<"Tuplam sonlar: ";
while (!tuplam.empty())
{
cout<tuplam.pop();
}
return 0;
}
Do'stlaringiz bilan baham: |
|
|