Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ZADANIE 1
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- class Point {
- public:
- float x,y;
- };
- bool comparex ( Point p1, Point p2) {
- return ( p1.x < p2.x);
- }
- bool comparey ( Point p1, Point p2) {
- return ( p1.y < p2.y);
- }
- int main()
- {
- Point p = Point();
- vector<Point> tab;
- for(int i = 9;i>=0;i--) {
- p.x = i;
- p.y = i+1;
- tab.push_back(p);
- }
- sort(tab.begin(), tab.end(), comparex);
- sort(tab.begin(), tab.end(), comparey);
- for(int i = 0;i<10;i++) {
- cout << tab[i].x <<endl;
- }
- return 0;
- }
- // ZAD 2
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- class Point {
- public:
- float x,y;
- Point(float x, float y) {
- this->x = x;
- this->y = y;
- }
- Point() {}
- };
- vector<Point> zad2(const vector<Point> &tab, Point p1, Point p2) {
- vector<Point> new_tab;
- for(int i = 0;i<(int)tab.size();i++) {
- if(tab[i].x >= p1.x && tab[i].y <= p1.y && tab[i].x <= p2.x && tab[i].y >= p2.y)
- new_tab.push_back(tab[i]);
- }
- return new_tab;
- }
- int main()
- {
- Point p = Point(1,3);
- Point p2 = Point(3,1);
- Point p3 = Point();
- vector<Point> tab;
- for(int i = 9;i>=0;i--) {
- p3.x = i;
- p3.y = i+1;
- tab.push_back(p3);
- }
- vector<Point> new_tab = zad2(tab, p,p2);
- for(int i = 0;i<(int)new_tab.size();i++) {
- cout << new_tab[i].x << new_tab[i].y<<endl;
- }
- return 0;
- }
- //ZAD 3
- #include <iostream>
- #include <list>
- using namespace std;
- void zad3(list<string>::iterator it1, list<string>::iterator it2) {
- while(it1 != it2) {
- cout<<*it1<<endl;
- it1++;
- }
- }
- int main()
- {
- list<string> list;
- for(int i = 0;i<10;i++) {
- list.push_back("str"+to_string(i));
- }
- std::list<string>::iterator it1 = list.begin();
- std::list<string>::iterator it2 = list.end();
- it1++;
- it2--;
- it2--;
- zad3(it1,it2);
- return 0;
- }
- //ZAD4
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- vector<int> zad4(vector<int> tab1, vector<int> tab2) {
- vector<int> new_tab;
- for(int i = 0;i<(int)tab1.size();i++) {
- new_tab.push_back(tab1[i]);
- }
- for(int i = 0;i<(int)tab2.size();i++) {
- new_tab.push_back(tab2[i]);
- }
- sort(new_tab.begin(),new_tab.end());
- new_tab.erase(unique(new_tab.begin(),new_tab.end()), new_tab.end());
- return new_tab;
- }
- int main()
- {
- vector<int> tab1;
- vector<int> tab2;
- for(int i = 0;i<10;i++) {
- tab1.push_back(i);
- tab2.push_back(i);
- }
- vector<int> tab3 = zad4(tab1,tab2);
- for(int i = 0;i<(int)tab3.size();i++) {
- cout<<tab3[i]<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement