fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. typedef struct field{
  6. char name[20];
  7. double cm,kg,BMI;
  8. struct field *next;
  9. int x;
  10. }cell;
  11.  
  12.  
  13. int main(void){
  14.  
  15. cell head,*a,*b,*new;
  16.  
  17.  
  18. head.next=NULL;
  19.  
  20. while(1){
  21. new=(cell*)malloc(sizeof(cell));
  22. scanf("%19s", new->name);
  23.  
  24. if(new->name[0]!='0'){
  25.  
  26. scanf("%lf",&new->cm);
  27. scanf("%lf",&new->kg);
  28.  
  29. new->BMI=new->kg/(0.0001*new->cm*new->cm);
  30.  
  31. a=&head;
  32.  
  33. while(a->next != NULL && new->BMI > a->next->BMI){
  34. a = a->next;
  35. }
  36.  
  37. new->next = a->next;
  38. a->next = new;
  39.  
  40. }
  41. else{
  42. break;
  43. }
  44.  
  45. }
  46.  
  47. for (a=head.next;a!=NULL;a=b){
  48. printf("%f %f %f %s\n",a->BMI,a->cm,a->kg,a->name);
  49. b = a->next;
  50. free(a);
  51. }
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0.01s 1856KB
stdin
manbo 145.3 48.7
ran 175.0 89.0
tako 156.3 66.6
ika 178.4 78.9
0 0 0
stdout
23.067351 145.300000 48.700000 manbo
24.790615 178.400000 78.900000 ika
27.261910 156.300000 66.600000 tako
29.061224 175.000000 89.000000 ran