Advertisement
Eddie_1337

13 atestat

Jan 24th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     ifstream f("atestat.in");
  8.     ofstream g("atestat.out");
  9.     struct coord {
  10.         int x, y, r;
  11.     } v[10], aux;
  12.     int n, ok = 0, nr = 0;
  13.     f >> n;
  14.     for (int i = 1; i <= n; i++) {
  15.         f >> v[i].x >> v[i].y >> v[i].r;
  16.         if (v[i].x == v[i].y)
  17.             nr++;
  18.     }
  19.     while (!ok) {
  20.         ok = 1;
  21.         for (int i = 1; i <= n - 1; i++)
  22.             if (v[i].r > v[i + 1].r) {
  23.                 aux.r = v[i].r; v[i].r = v[i + 1].r; v[i + 1].r = aux.r;
  24.                 aux.y = v[i].y; v[i].y = v[i + 1].y; v[i + 1].y = aux.y;
  25.                 aux.x = v[i].x; v[i].x = v[i + 1].x; v[i + 1].x = aux.x;
  26.                 ok = 0;
  27.             }
  28.     }
  29.     for (int i = 1; i <= n; i++)
  30.         g << "(" << v[i].x << "," << v[i].y << "," << v[i].r << ")" << endl;
  31.     g << nr;
  32.     f.close();
  33.     g.close();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement