Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. //ZADANIE 1
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. class Point {
  11. public:
  12. float x,y;
  13. };
  14.  
  15. bool comparex ( Point p1, Point p2) {
  16. return ( p1.x < p2.x);
  17. }
  18. bool comparey ( Point p1, Point p2) {
  19. return ( p1.y < p2.y);
  20. }
  21.  
  22. int main()
  23. {
  24. Point p = Point();
  25. vector<Point> tab;
  26. for(int i = 9;i>=0;i--) {
  27. p.x = i;
  28. p.y = i+1;
  29. tab.push_back(p);
  30. }
  31. sort(tab.begin(), tab.end(), comparex);
  32. sort(tab.begin(), tab.end(), comparey);
  33.  
  34. for(int i = 0;i<10;i++) {
  35. cout << tab[i].x <<endl;
  36. }
  37.  
  38. return 0;
  39. }
  40.  
  41. // ZAD 2
  42.  
  43. #include <iostream>
  44. #include <vector>
  45. #include <algorithm>
  46.  
  47. using namespace std;
  48.  
  49.  
  50. class Point {
  51. public:
  52. float x,y;
  53. Point(float x, float y) {
  54. this->x = x;
  55. this->y = y;
  56. }
  57. Point() {}
  58. };
  59.  
  60. vector<Point> zad2(const vector<Point> &tab, Point p1, Point p2) {
  61. vector<Point> new_tab;
  62. for(int i = 0;i<(int)tab.size();i++) {
  63. if(tab[i].x >= p1.x && tab[i].y <= p1.y && tab[i].x <= p2.x && tab[i].y >= p2.y)
  64. new_tab.push_back(tab[i]);
  65. }
  66. return new_tab;
  67. }
  68.  
  69. int main()
  70. {
  71. Point p = Point(1,3);
  72. Point p2 = Point(3,1);
  73. Point p3 = Point();
  74. vector<Point> tab;
  75. for(int i = 9;i>=0;i--) {
  76. p3.x = i;
  77. p3.y = i+1;
  78. tab.push_back(p3);
  79. }
  80.  
  81. vector<Point> new_tab = zad2(tab, p,p2);
  82.  
  83. for(int i = 0;i<(int)new_tab.size();i++) {
  84. cout << new_tab[i].x << new_tab[i].y<<endl;
  85. }
  86.  
  87. return 0;
  88. }
  89.  
  90. //ZAD 3
  91.  
  92. #include <iostream>
  93. #include <list>
  94.  
  95. using namespace std;
  96.  
  97. void zad3(list<string>::iterator it1, list<string>::iterator it2) {
  98. while(it1 != it2) {
  99. cout<<*it1<<endl;
  100. it1++;
  101. }
  102. }
  103.  
  104.  
  105. int main()
  106. {
  107.  
  108. list<string> list;
  109. for(int i = 0;i<10;i++) {
  110. list.push_back("str"+to_string(i));
  111. }
  112. std::list<string>::iterator it1 = list.begin();
  113. std::list<string>::iterator it2 = list.end();
  114. it1++;
  115. it2--;
  116. it2--;
  117. zad3(it1,it2);
  118. return 0;
  119. }
  120.  
  121. //ZAD4
  122.  
  123. #include <iostream>
  124. #include <vector>
  125. #include <algorithm>
  126.  
  127. using namespace std;
  128.  
  129. vector<int> zad4(vector<int> tab1, vector<int> tab2) {
  130. vector<int> new_tab;
  131. for(int i = 0;i<(int)tab1.size();i++) {
  132. new_tab.push_back(tab1[i]);
  133. }
  134. for(int i = 0;i<(int)tab2.size();i++) {
  135. new_tab.push_back(tab2[i]);
  136. }
  137. sort(new_tab.begin(),new_tab.end());
  138. new_tab.erase(unique(new_tab.begin(),new_tab.end()), new_tab.end());
  139.  
  140. return new_tab;
  141. }
  142.  
  143.  
  144. int main()
  145. {
  146.  
  147. vector<int> tab1;
  148. vector<int> tab2;
  149.  
  150. for(int i = 0;i<10;i++) {
  151. tab1.push_back(i);
  152. tab2.push_back(i);
  153. }
  154. vector<int> tab3 = zad4(tab1,tab2);
  155. for(int i = 0;i<(int)tab3.size();i++) {
  156. cout<<tab3[i]<<endl;
  157. }
  158. return 0;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement