You are viewing a single comment's thread. Return to all comments →
struct triangle { int a; int b; int c; };
typedef struct triangle triangle; void sort_by_area(triangle* tr, int n) { double t,area[n]; for(int i=0; iarea[j+1]){ triangle temp=tr[j]; tr[j]=tr[j+1]; tr[j+1]=temp; } } } }
int main() { int n; scanf("%d", &n); triangle *tr = malloc(n * sizeof(triangle)); for (int i = 0; i < n; i++) { scanf("%d%d%d", &tr[i].a, &tr[i].b, &tr[i].c); } sort_by_area(tr, n); for (int i = 0; i < n; i++) { printf("%d %d %d\n", tr[i].a, tr[i].b, tr[i].c); } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Small Triangles, Large Triangles
You are viewing a single comment's thread. Return to all comments →
include
include
include
struct triangle { int a; int b; int c; };
typedef struct triangle triangle; void sort_by_area(triangle* tr, int n) { double t,area[n]; for(int i=0; iarea[j+1]){ triangle temp=tr[j]; tr[j]=tr[j+1]; tr[j+1]=temp; } } } }
int main() { int n; scanf("%d", &n); triangle *tr = malloc(n * sizeof(triangle)); for (int i = 0; i < n; i++) { scanf("%d%d%d", &tr[i].a, &tr[i].b, &tr[i].c); } sort_by_area(tr, n); for (int i = 0; i < n; i++) { printf("%d %d %d\n", tr[i].a, tr[i].b, tr[i].c); } return 0; }