char turidagi to’plam(set) berilgan. Undagi unli harflarni char turidagi A to’plamga, undoshlarini B to’plamga o‘zlashtiruvchi dastur tuzing.
#include
#include
using namespace std;
int main() {
set inputSet = {'a', 'b', 'c', 'a', 'd', 'e', 'b', 'f', 'g', 'h', 'h'};
set A, B;
for (auto it = inputSet.begin(); it != inputSet.end(); ++it) {
if (*it >= 'a' && *it <= 'z') {
A.insert(*it);
} else {
B.insert(*it);} }
cout << "A to'plami: ";
for (auto it = A.begin(); it != A.end(); ++it) {
cout << *it << " ";}
cout << endl;
cout << "B to'plami: ";
for (auto it = B.begin(); it != B.end(); ++it) {
cout << *it << " ";}
cout << endl;
return 0;}
|
X va Y ikkita to’plam(set) berilgan. X va Y to‘plamlarining musbat qiymatlilaridan Z to‘plamni tashkil etuvchi dastur tuzing
#include
#include
using namespace std;
int main() {
set X = {1, 2, 3, 4, 5};
set Y = {3, 4, 5, 6, 7};
set Z;
for (auto it = X.begin(); it != X.end(); ++it) {
if (*it > 0) {
Z.insert(*it);
}}
for (auto it = Y.begin(); it != Y.end(); ++it) {
if (*it > 0) {
Z.insert(*it);
}}
cout << "Z to'plami: ";
for (auto it = Z.begin(); it != Z.end(); ++it) {
cout << *it << " ";
}
cout << endl;
return 0;}
|
X va Y ikkita to’plam(set) berilgan. X va Y to‘plamlarining juft qiymatlilaridan Z to‘plamni tashkil etuvchi dastur tuzing
#include
#include
using namespace std;
int main() {
set X = {1, 2, 3, 4, 5};
set Y = {3, 4, 5, 6, 7};
set Z;
for (auto it = X.begin(); it != X.end(); ++it) {
if (*it % 2 == 0) { Z.insert(*it);}}
for (auto it = Y.begin(); it != Y.end(); ++it) {
if (*it % 2 == 0) { // juft sonlarni Z to'plamiga qo'shamiz
Z.insert(*it); }}
cout << "Z to'plami: ";
for (auto it = Z.begin(); it != Z.end(); ++it) {
cout << *it << " ";}
cout << endl;
return 0;}
|
|
Do'stlaringiz bilan baham: |