erehh

surjective function discrete maths

May 23rd, 2023
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include<iostream>
  2. #include<set>
  3. #include<map>
  4. using namespace std;
  5. int f(int x) {
  6. return 4 * x - 7;
  7. }
  8. int g(int x) {
  9. return x * x;
  10. }
  11. bool sureqcia(map <int, int> m, set<int> codom) {
  12. set<int> s;
  13. for (auto im = m.begin(); im != m.end(); im++)
  14. s.insert(im->second); //anasaxebis simravle
  15. for (auto i = codom.begin(); i != codom.end(); i++) {
  16. if (s.find(*i)==s.end()) //codomeinshi edzebs elements, romelic ar aris
  17. anasaxebis simravlesi
  18. { return false; break; }
  19. }
  20. return true;
  21. }
  22. int main() {
  23. set<int> dom{ -1,-2,1,2};
  24. set<int> codomf{ -11,-15,-3,1};
  25. set<int> codomg{ 1,4,-4 };
  26. map<int, int> mf, mg;
  27. cout << "dom={";
  28. for (auto i = dom.begin(); i != dom.end(); i++) {
  29. cout << *i << ",";
  30. }
  31. cout << "}\n" << endl;
  32. cout << "codomf={";
  33. for (auto i = codomf.begin(); i != codomf.end(); i++) {
  34. cout << *i << ",";
  35. }
  36. cout << "}\n" << endl;
  37.  cout << "codomg={";
  38. for (auto i = codomg.begin(); i != codomg.end(); i++) {
  39. cout << *i << ",";
  40. }
  41. cout << "}\n" << endl;
  42. for (auto i = dom.begin(); i != dom.end(); i++) {
  43. mf[*i] = f(*i); //vqmnit wyvilebis simravles, (i, f(i)), sadac i dom-is
  44. elementia
  45. if (mf.find(*i) == mf.end())
  46. {cout << " asaxva ar aris funqcia\n"; return 0;}
  47. }
  48. cout << "mf: ";
  49. for (auto i = mf.begin(); i != mf.end(); i++)
  50. cout << "(" << i->first << ";" << i->second << "), ";
  51. cout << endl;
  52. if (sureqcia(mf, codomf)) cout << " f sureqciaa \n";
  53. else cout << "f ar aris sureqcia \n";
  54. for (auto i = dom.begin(); i != dom.end(); i++) {
  55. mg[*i] = g(*i); //vqmnit wyvilebis simravles, (i, g(i)), sadac i dom-is
  56. elementia
  57. }
  58. cout << endl;
  59. cout << "mg: ";
  60. for (auto i = mg.begin(); i != mg.end(); i++)
  61. cout << "(" << i->first << ";" << i->second << "), ";
  62. cout << endl;
  63. if (sureqcia(mg, codomg)) cout << "g sureqciaa \n";
  64. else cout << "g ar aris sureqcia \n";
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment