Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- struct Punkt { double x, y; };
- struct Okrag { int x, y, r; };
- bool styczny(Okrag o)
- {
- return abs(o.y) == o.r;
- }
- void sortowanie(std::vector<Okrag> &v)
- {
- std::sort(v.begin(), v.end(), [](Okrag o1, Okrag o2) { if (o1.x == o2.x) return o2.y <= o1.y;
- else return o1.x <= o2.x; });
- }
- void sortowanie_p(std::vector<Punkt> &v)
- {
- std::sort(v.begin(), v.end(), [](Punkt o1, Punkt o2) { if (o1.x == o2.x) return o2.y <= o1.y;
- else return o1.x <= o2.x; });
- }
- double pole(Punkt a, Punkt b, Punkt c)
- {
- // P = 1/2 * |xA*yB + xB*yC + xC*yA - xC*yB - xA*yC - xB*yA
- return 1.0f / 2.0f * abs(a.x * b.y + b.x * c.y + c.x * a.y - c.x * b.y - a.x * c.y - b.x * a.y);
- }
- int main()
- {
- std::vector<Punkt> punkty;
- std::vector<Okrag> okregi;
- std::ifstream dane1("punkty.txt");
- std::ifstream dane2("okregi.txt");
- while (!dane1.eof())
- {
- Punkt p;
- dane1 >> p.x >> p.y;
- punkty.emplace_back(p);
- }
- while (!dane2.eof())
- {
- Okrag o;
- dane2 >> o.x >> o.y >> o.r;
- okregi.emplace_back(o);
- }
- // 4.1
- int c1, c2, c3, c4;
- c1 = c2 = c3 = c4 = 0;
- for (auto &punkty : punkty)
- {
- if (punkty.x > 0 && punkty.y > 0) c1++;
- if (punkty.x < 0 && punkty.y > 0) c2++;
- if (punkty.x < 0 && punkty.y < 0) c3++;
- if (punkty.x > 0 && punkty.y < 0) c4++;
- }
- std::ofstream w1("wynik1.txt");
- w1 << c1 << " " << c2 << " " << c3 << " " << c4;
- // 4.2
- std::vector<Okrag> styczne;
- for (auto& okrag : okregi)
- if (styczny(okrag))
- styczne.emplace_back(okrag);
- sortowanie(styczne);
- std::ofstream w2("wynik2.txt");
- for (auto &okrag : styczne)
- w2 << okrag.x << " " << okrag.y << " " << okrag.r << std::endl;
- w2 << styczne.size();
- // 4.3
- // Sortowanie zeby moc obliczyc pole
- sortowanie_p(punkty);
- double polec = 0.0f;
- for (int i = 0; i < punkty.size() - 3; i++)
- polec += pole(punkty[i], punkty[i + 1], punkty[i + 2]);
- std::ofstream w3("wynik3.txt");
- w3 << (int) polec;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement