Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct Point {
- int x;
- int y;
- } Point;
- void bsort(Point *p, int n) {
- int s = 0;
- do {
- s = 1;
- for (int i = 1; i < n; i++) {
- if (p[i - 1].y > p[i].y) {
- Point aux = p[i];
- p[i] = p[i - 1];
- p[i - 1] = aux;
- s = 0;
- }
- }
- } while(!s);
- }
- int main() {
- int n;
- scanf("%d", &n);
- Point *points = (Point *) malloc(n * sizeof(Point));
- for (int i = 0; i < n; i++) {
- scanf("%d %d", &points[i].x, &points[i].y);
- }
- bsort(points, n);
- int currentY = points[0].y;
- printf("Puncte pe linia orizontală y = %d: [%d", currentY, points[0].x);
- for (int i = 1; i < n; i++) {
- if (points[i].y != currentY) {
- currentY = points[i].y;
- printf("]\nPuncte pe linia orizontală y = %d: [%d", currentY, points[i].x);
- } else {
- printf(", %d", points[i].x);
- }
- }
- printf("]\n");
- free(points);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement