Dasturlash3


Download 145.09 Kb.
Pdf ko'rish
Sana16.06.2023
Hajmi145.09 Kb.
#1516066
Bog'liq
Dasturlash3



Dasturlash. 2. Fanımdan. 2.. Labaratoriya ishi
Nig`monov Elyor
18-variant
1. Berilgan float turidagi to’plam qiymatlarining juftlari 2-va 3- to’plamda nechta 
marta qatnashganligini aniqlovchi va ularni ekranga chiqaruvchi dastur tuzing. 
Ikkala to’plamdan ham bir xil qiymatli elemetlar o’chirilib Saralangan to’plam 
hosil qilinsin hamda uning qiymatlari ekranga chiqarilsin. Berilgan to’plam 
qiymatlarining juftlari yig’indisi hisoblansin. 
#include

#include

using namespace std;
int main() {
float n,x;
cout << "To'plam elementlari soni: "; cin >> n;
set a;
multiset b;
for (int i = 0; i < n; i++) {
cin >> x;
a.insert(x);
}
cout << "To'plam elementlari soni: "; cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
b.insert(x);
}
for (auto i = a.begin(); i != a.end(); i++) {
if (*i % 2 == 0) {
cout << *i << ": ";
if (b.find(*i) != b.end()) {
cout<< b.count(*i);
cout << " marta qatnashgan" << endl;
}
else {
cout << "0 marta qatnashgan" << endl;
}
}


}
for (auto i = b.begin(); i != b.end(); i++) {
a.insert(*i);
}
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
return 0;
}


2. Topshiriq
To’plamning takrorlangan kalitlarning qiymatlarini chop etuvchi dastur tuzing. 
#include  
#include  
#include  
using namespace std
int main() 

multimap gquiz1; 
gquiz1.insert(pair(1, 40)); 
gquiz1.insert(pair(2, 30)); 
gquiz1.insert(pair(3, 60)); 
gquiz1.insert(pair(6, 50)); 
gquiz1.insert(pair(6, 10)); 
multimap::iterator itr; 
cout << "\nThe multimap gquiz1 is : \n"; 
cout << "\tKEY\tELEMENT\n"; 
for (itr =
gquiz1.begin(); itr != gquiz1.end(); ++itr) { 
cout << '\t' << itr->first << '\t' << itr->second 
<< '\n'; 

cout << endl; 
gquiz1.insert(pair(4, 50)); 
gquiz1.insert(pair(5, 10)); 
cout << "\nThe multimap gquiz1 after adding extra " 
"elements is : \n"; 
cout << "\tKEY\tELEMENT\n"; 
for (itr = gquiz1.begin(); itr != gquiz1.end(); ++itr) { 
cout << '\t' << itr->first << '\t' << itr->second 
<< '\n'; 

cout << endl; 


multimap gquiz2(gquiz1.begin(), gquiz1.end()); 
cout << "gquiz1.lower_bound(5) : " 
<< "\tKEY = "; 
cout << gquiz1.lower_bound(5)->first << '\t'; 
cout << "\tELEMENT = " << gquiz1.lower_bound(5)->second 
<< endl; 
cout << "gquiz1.upper_bound(5) : " 
<< "\tKEY = "; 
cout << gquiz1.upper_bound(5)->first << '\t'; 
cout << "\tELEMENT = " << gquiz1.upper_bound(5)->second 
<< endl; 
return 0; 


Download 145.09 Kb.

Do'stlaringiz bilan baham:




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