axeefectushka

Untitled

Feb 4th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "stdio.h"
  3. #include "string.h"
  4. #include "windows.h"
  5.  
  6. #define _CRT_SECURE_NO_WARNINGS
  7.  
  8. int main()
  9. {
  10. SetConsoleCP(1251);
  11. SetConsoleOutputCP(1251);
  12. struct list
  13. {
  14. char name[100];
  15. int number;
  16. char group[100];
  17.  
  18. };
  19. char s[100];
  20. int count,countconst;
  21. int size1=0, size2=0;
  22. int i,j;
  23. struct list temp;
  24. struct list mas[10];
  25.  
  26. FILE *f1;
  27. f1 = fopen("1.txt", "r");
  28. while (!feof(f1))
  29. {
  30. fgets(s, 100, f1);
  31. size1++;
  32. count = strlen(s);
  33. while (s[count] != ' ')
  34. count--;
  35. countconst = count;
  36. for (i = 0; i < 6; i++)
  37. {
  38. mas[size1 - 1].group[i] = s[count + 1];
  39. count++;
  40. }
  41. mas[size1 - 1].group[6] = '\0';
  42. for (i = 0; i < countconst; i++)
  43. {
  44. mas[size1 - 1].name[i] = s[i];
  45.  
  46. }
  47. mas[size1 - 1].name[countconst] = '\0';
  48.  
  49. }
  50. fclose(f1);
  51.  
  52. FILE *f2;
  53. f2 = fopen("2.txt", "r");
  54. while (!feof(f2))
  55. {
  56. fgets(s, 100, f1);
  57. size1++;
  58. count = strlen(s);
  59. while (s[count] != ' ')
  60. count--;
  61. countconst = count;
  62. for (i = 0; i < 6; i++)
  63. {
  64. mas[size1 - 1].group[i] = s[count + 1];
  65. count++;
  66. }
  67. mas[size1 - 1].group[6] = '\0';
  68. for (i = 0; i < countconst; i++)
  69. {
  70. mas[size1 - 1].name[i] = s[i];
  71.  
  72. }
  73. mas[size1 - 1].name[countconst] = '\0';
  74.  
  75. }
  76. fclose(f2);
  77.  
  78. for (i = 0; i<size1 - 1; i++)
  79. for (j = size1 - 2; j >= i; j--)
  80. if (strcmp(mas[j].name, mas[j + 1].name)>0)
  81. {
  82. temp = mas[j];
  83. mas[j] = mas[j + 1];
  84. mas[j + 1] = temp;
  85. }
  86.  
  87.  
  88. FILE *f3;
  89. f3 = fopen("result.txt","w");
  90. for (i = 0; i < size1; i++)
  91. {
  92. mas[i].number = i + 1;
  93. fprintf(f1, "%d ", mas[i].number);
  94. fprintf(f1, "%s ", mas[i].name);
  95. fprintf(f1, "%s\n", mas[i].group);
  96. }
  97. fclose(f3);
  98. system("pause");
  99.  
  100.  
  101. }
Add Comment
Please, Sign In to add comment