Advertisement
J00ker

ExI

Feb 24th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. #include <ctime>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8.  
  9. struct elev
  10. {
  11. char id[6];
  12. char nume[40];
  13. char scoala[50];
  14. }t[100];
  15.  
  16. int n;
  17.  
  18.  
  19. void Separa(char s[200])
  20. {
  21. char x[50];
  22. int k = 0, i;
  23.  
  24. for(i = 0; s[i] != '-'; i++)
  25. x[k++] = s[i];
  26. x[k] = 0;
  27. while(x[k-1] == ' ')
  28. {
  29. x[k-1] = 0;
  30. k--;
  31. }
  32. strcpy(t[n].id, x);
  33. i++;
  34. for(; s[i] != '-'; i++)
  35. x[k++] = s[i];
  36. x[k] = 0;
  37. while(x[k-1] == ' ')
  38. {
  39. x[k-1] = 0;
  40. k--;
  41. }
  42. strcpy(t[n].nume, x);
  43. i++;
  44. while(s[i] == ' ') i++;
  45. strcpy(x, s+i);
  46. k = strlen(x);
  47. while(x[k-1] == ' ')
  48. {
  49. x[k-1] = 0;
  50. k--;
  51. }
  52. strcpy(t[n].scoala, x);
  53. }
  54. void Citire()
  55. {
  56. char s[200];
  57. n = 0;
  58. ifstream fin("elevi.txt");
  59. fin.getline(s, 199);
  60. while(strcmp(s, "***") != 0)
  61. {
  62. Separa(s);
  63. n++;
  64. fin.getline(s, 199);
  65. }
  66. for(int i = 0; i < n; i++)
  67. cout << t[i].id << "*" << t[i].nume << "*" << t[i].scoala << "\n";
  68. fin.close();
  69. }
  70.  
  71. void Amesteca()
  72. {
  73. int i, j, k;
  74. elev x;
  75. srand(time(0));
  76. for(k = 1; k <= 100000; k++)
  77. {
  78. i = rand() % n;
  79. j = rand() % n;
  80. swap(t[i], t[j]);
  81. }
  82. for(i = 1; i < n;)
  83. {
  84. if((t[i].id == t[i+1].id)||(t[i].id == t[i-1].id))
  85. {
  86. x = t[i];
  87. for(j = i+1; j < n-1; j++)
  88. t[j] = t[j+1];
  89. t[n-1] = x;
  90. }
  91. else i++;
  92. }
  93. for(i = 0; i < n; i++)
  94. cout << t[i].id;
  95. }
  96.  
  97. void Afisare()
  98. {
  99. ofstream fout("elevi.out");
  100. for(int i = 0; i < n; i++)
  101. fout << t[i].id << " " << t[i].nume << " " << t[i].scoala << "\n";
  102. fout << "\n";
  103. fout.close();
  104. }
  105.  
  106. int main()
  107. {
  108. Citire();
  109. Amesteca();
  110.  
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement