Przykładowy program który tłumaczy typ/ strukturę „set” w języku C++
* jak użyć?
* dlaczego?
* właściwości
–
Zadanie pochodzi z zajęć Olimpijskiego Koła Informatycznego:
https://oki.org.pl/harmonogram-zajec/
https://oki.org.pl/harmonogram-zajec/
–
Typ „set” pomaga rozwiązać problemy na Olimpiadzie Informatycznej ale również te które trzeba rozwiązać w realnym świecie.
——-
Poniżej kod użyty w powyższym omówieniu:
–
#include <bits/stdc++.h>
using namespace std;
int main() {
int i;
set teksty;
set::iterator it;
teksty.insert ("kot");
teksty.insert ("ma");
teksty.insert ("ale");
teksty.insert ("uwaga!!!");
teksty.insert ("ale");
teksty.insert ("ale");
teksty.insert ("nie");
teksty.insert ("chwali");
teksty.insert ("sie");
teksty.insert ("wcale!!!");
for (it=teksty.begin(); it!=teksty.end(); ++it ) {
cout << *it << "\n";
}
cout << "\n";
it = teksty.upper_bound ("a");
cout << "teksty upper_bound (a): " << *it << "\n";
it = teksty.upper_bound ("ale");
cout << "teksty upper_bound (ale): " << *it << "\n";
it = teksty.upper_bound ("c");
cout << "teksty upper_bound (c): " << *it << "\n";
it = teksty.upper_bound ("z");
if ( it == teksty.end() )
cout << "poza!\n";
else
cout << "teksty upper_bound (z): " << *it << "\n";
return 0;
}
