Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef struct
  4. {
  5.  
  6. int matr;
  7. int d;
  8. int m;
  9. int a;
  10. char nome[200];
  11.  
  12. }Aluno;
  13.  
  14. //Compara idade de a e b
  15. // @return 1: a > b 0: a = b -1: a < b
  16. int aluno_cpm(const Aluno* a, const Aluno* b);
  17.  
  18. int main()
  19. {
  20. int n;
  21. int i,i2;
  22. Aluno turma[30];
  23. Aluno a;
  24.  
  25. scanf("%d",&n);
  26.  
  27. scanf("%d",&a.matr);
  28. scanf("%d",&a.d);
  29. scanf("%d",&a.m);
  30. scanf("%d",&a.a);
  31. scanf("%[^\n]",a.nome);
  32.  
  33. turma[0] = a;
  34.  
  35. for(i = 1; i < n; ++i)
  36. {
  37. scanf("%d",&a.matr);
  38. scanf("%d",&a.d);
  39. scanf("%d",&a.m);
  40. scanf("%d",&a.a);
  41. scanf("%[^\n]",a.nome);
  42.  
  43. turma[i] = a;
  44.  
  45. for(i2 = i; i2 > 0; --i2)
  46. {
  47. if(aluno_cpm(&turma[i2],&turma[i2-1]) < 0)
  48. {
  49. a = turma[i2];
  50. turma[i2] = turma[i2-1];
  51. turma[i2-1] = a;
  52. }
  53. }
  54. }
  55.  
  56. for(i = 0; i < n; ++i)
  57. {
  58.  
  59. printf("Matric.: %d Nome: %s Data Nasc.: %d/%d/%d\n",turma[i].matr
  60. ,turma[i].nome
  61. ,turma[i].d
  62. ,turma[i].m
  63. ,turma[i].a);
  64. }
  65.  
  66. return 0;
  67. }
  68.  
  69. int aluno_cpm(const Aluno* a, const Aluno* b)
  70. {
  71. int result = 0;
  72.  
  73. if(a->a < b->a) result = 1;
  74. else if(a->a > b->a) result = -1;
  75. else if(a->m < b->m) result = 1;
  76. else if(a->m > b->m) result = -1;
  77. else if(a->d < b->d) result = 1;
  78. else if(a->d > b->d) result = -1;
  79.  
  80. return result;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement