Navbat eng kichik elementi o„chirilsin


Download 101.75 Kb.
Sana14.12.2022
Hajmi101.75 Kb.
#1005562
Bog'liq
9-Amaliyot. (Navbat)

Topshiriq





  1. Navbat eng kichik elementi o„chirilsin.

#include
#include
using namespace std;
int main(){
int n,max1 = INT_MIN; cin>>n;
queuea,b;
int maxi;
for (int i=1; i<=n; i++){
int k; cin>>k;
a.push(k);
max1 = max(max1,k);
if (max1 == k)
maxi = i;
}
int d=1;
while (!a.empty()){
if (d!=maxi){
b.push(a.front());
}
a.pop();
d++;
}
while (!b.empty()){
cout<b.pop();
}
}


  1. Navbatda birinchi elementga teng barcha elementlar o„chirilsin.

#include
#include
using namespace std;
int main(){
int n,max1 = INT_MIN; cin>>n;
queuea,b;
int maxi;
for (int i=1; i<=n; i++){
int k; cin>>k;
a.push(k);
}
int birinchi = a.front();
int d=1;
while (!a.empty()){
if (a.front()!=birinchi){
b.push(a.front());
}
a.pop();
d++;
}
while (!b.empty()){
cout<b.pop();
}
}




  1. Navbatda oxirgi elementga teng barcha elementlar o„chirilsin.

#include
#include
using namespace std;
int main(){
int n; cin>>n;
queuea,b;
for (int i=1; i<=n; i++){
int k; cin>>k;
a.push(k);
}
int oxirgi = a.back();
while (!a.empty()){
if (a.front()!=oxirgi){
b.push(a.front());
}
a.pop();
}
while (!b.empty()){
cout<b.pop();
}
}




  1. Navbat eng katta elementi o„chirilsin.

#include
#include
using namespace std;
int main(){
int n,max1 = INT_MIN; cin>>n;
queuea,b;
int maxi;
for (int i=1; i<=n; i++){
int k; cin>>k;
a.push(k);
max1 = max(max1,k);
if (max1 == k)
maxi = i;
}
int d=1;
while (!a.empty()){
if (d!=maxi){
b.push(a.front());
}
a.pop();
d++;
}
while (!b.empty()){
cout<b.pop();
}
}


Download 101.75 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling