myname0

квик

Apr 27th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. struct Student
  9. {
  10. string surname;
  11. string name;
  12. string patronymic;
  13. int year;
  14. int marks [5];
  15. };
  16.  
  17. void qsort(Student *a, int l, int r)
  18. {
  19. int i = l, j = r;
  20. string p = a[(i + j) / 2].surname;
  21. while ( i <= j )
  22. {
  23. while ( a[i].surname < p ) i++;
  24. while ( p < a[j].surname ) j--;
  25. if (i <= j)
  26. {
  27. swap (a[i], a[j]);
  28. i++; j--;
  29. }
  30. }
  31.  
  32. if ( l < j ) qsort(a, l, j);
  33. if ( i < r ) qsort(a, i, r);
  34. }
  35. int main()
  36. {
  37. int n=0;
  38. Student list [100];
  39. ifstream inp ("list.txt");
  40. setlocale(LC_ALL,"Russian");
  41. while (inp.peek()!=EOF)
  42. {
  43. inp >> list[n].surname;
  44. inp >> list[n].name;
  45. inp >> list[n].patronymic;
  46. inp >> list[n].year;
  47. for(int i=0; i < 5; i++)
  48. inp >> list[n].marks[i];
  49. n++;
  50. }
  51. qsort(list, 0, n-1);
  52. ofstream out ("list2.txt");
  53. for( int i = 0; i < n; i++)
  54. {
  55. out << list[i].surname << " " << list[i].name << " " << list[i].patronymic << " " << list[i].year << " ";
  56. for(int j = 0; j < 5; j++)
  57. out << list[i].marks[j] << " ";
  58. out << endl;
  59. }
  60. inp.close();
  61. out.close();
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment