Guest User

Untitled

a guest
Jan 12th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<conio.h>
  4. typedef enum{
  5. milioane,miliarde
  6. };
  7.  
  8. typedef struct{
  9. int loc, suma;
  10. char nume[20],sport[20];
  11. }Sportiv;
  12. Sportiv s[20];
  13. int n;
  14.  
  15. void citire()
  16. {
  17. FILE *f;
  18. f=fopen("sportivi.txt", "rt");
  19. if(f==NULL)
  20. {
  21. printf("fisierul nu se poate deschide!");
  22. }
  23. else
  24. {
  25. while(!feof(f))
  26. {
  27. fscanf(f, "%d %s %s %d", &s[n].loc, s[n].nume, s[n].sport, &s[n].suma);
  28. }
  29. }
  30. }
  31.  
  32. void afisare()
  33. {
  34. int i;
  35. for(i=0;i<n;i++)
  36. printf( "%d %s %s %d\n", s[i].loc, s[i].nume, s[i].sport, s[i].suma);
  37. }
  38.  
  39. int Linary(char nume[20])
  40. {
  41. int i;
  42. for(i=0;i<n;i++)
  43. if(strcmp(s[i].nume, nume)==0)
  44. return i;
  45. return i;
  46. }
  47.  
  48. void Shellsort()
  49. {
  50. int h[3]={ 3,2,1 };
  51. int i, j, w, k;
  52. Sportiv aux;
  53. for(w=0; w<3; w++)
  54. {
  55. k=h[w];
  56. for(i=k; i<n; i++)
  57. {
  58. aux= s[i];
  59. j=i-k;
  60. if(j>=0 && strcmp(s[j].nume, aux.nume)>0)
  61. {
  62. s[j+k]=s[j];
  63. j-=k;
  64. }
  65. s[j+k]=aux;
  66. }
  67. }
  68. }
  69.  
  70. int main()
  71. {
  72. int i, opt;
  73. char nume[20];
  74.  
  75. do
  76. {
  77. printf("~~~~~Meniu~~~~~\n");
  78. printf("1.Citire informatii.\n");
  79. printf("2.Afisare informaii.\n");
  80. printf("3.Cautare informatii.\n");
  81. printf("4.Sortare informatii.\n");
  82. printf("Introduceti o optiune: \n");
  83. scanf("%d", &opt);
  84. switch (opt)
  85. {
  86. case 1:
  87. citire();
  88. break;
  89. case 2:
  90. afisare();
  91. break;
  92. case 3:
  93. printf("introduceti numele cautat: ");
  94. scanf("%s", nume);
  95. i=Linary(nume);
  96. if (i != n)
  97. printf("%d %s %s %d", s[i].loc, s[i].nume, s[i].sport, s[i].suma);
  98. else
  99. printf("Nu exista");
  100. break;
  101. case 4:
  102. Shellsort();
  103. afisare();
  104. break;
  105. default:
  106. printf("optiunea introdusa nu exista!\n");
  107. break;
  108. }
  109. }while(opt !=4);
  110. _getch();
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment