Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct student{
  5. char first_name[15];
  6. char last_name[20];
  7. int number;
  8. int points;
  9. }student;
  10.  
  11. void norm(char *ime) {
  12.      int i=0;
  13.      ime[i]=toupper(ime[i]);
  14.      for(i=1;i<strlen(ime);++i){
  15.             ime[i]=tolower(ime[i]);
  16.      }
  17. }
  18.  
  19. int compare (void *a, void *b)
  20. {
  21.   return ( *(int*)a - *(int*)b );
  22. }
  23.  
  24. int main() {
  25. struct student st[50];
  26. int i, n;
  27. scanf("%d", &n);
  28. for (i = 0; i < n; ++i) {
  29. scanf("%s", &st[i].first_name);
  30. scanf("%s", &st[i].last_name);
  31. scanf("%d", &st[i].number);
  32. int j, zadaca;
  33. st[i].points = 0;
  34. for(j = 0; j < 4; j++) {
  35. scanf("%d", &zadaca);
  36. st[i].points += zadaca;
  37. }
  38. norm(st[i].first_name);
  39. norm(st[i].last_name);
  40. }
  41. qsort(st, n, sizeof(*st), compare);
  42. for (i = 0; i < n; i++) {
  43. printf("%d. %s %s\t%d\t%d\n", i + 1, st[i].first_name, st[i].last_name, st[i].number, st[i].points);
  44. }
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement