Last active
May 14, 2017 21:59
-
-
Save skhozinova/281b2d007a688f9afed9dc577cab6626 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<string.h> | |
#include<stdlib.h> | |
#include<conio.h> | |
#include<windows.h> | |
//Переписать данные из файла data.txt в файл outdata.txt, отсортировав их: | |
//по возрастанию количества «пятерок» методом простого выбора (количество пятерок вывести в файл outdata.txt для каждого студента) | |
// Функция сортировки прямым выбором | |
void selectionSort(int *num, int size) | |
{ | |
int min, temp; // для поиска минимального элемента и для обмена | |
for (int i = 0; i < size - 1; i++) | |
{ | |
min = i; // запоминаем индекс текущего элемента | |
// ищем минимальный элемент чтобы поместить на место i-ого | |
for (int j = i + 1; j < size; j++) // для остальных элементов после i-ого | |
{ | |
if (num[j] < num[min]) // если элемент меньше минимального, | |
min = j; // запоминаем его индекс в min | |
} | |
temp = num[i]; // меняем местами i-ый и минимальный элементы | |
num[i] = num[min]; | |
num[min] = temp; | |
} | |
} | |
struct student | |
{ | |
char a[20]; | |
char b[20]; | |
char c[20]; | |
char d[20]; | |
char e[20]; | |
char f[5]; | |
char col[5]; | |
} student[7]; | |
int main(void) | |
{ int count; | |
FILE *fp; | |
if((fp= fopen("data.txt","r"))== NULL) | |
{ | |
printf("Can't open file!"); | |
return 1; | |
} | |
for(int i=0;i<7; i++) | |
{ | |
fscanf(fp,"%s", student[i].a); | |
fscanf(fp,"%s", student[i].b); | |
fscanf(fp,"%s", student[i].c); | |
fscanf(fp,"%s", student[i].d); | |
fscanf(fp,"%s", student[i].e); | |
fscanf(fp,"%s", student[i].f); | |
} | |
fclose(fp); | |
FILE *ft; | |
if((ft= fopen("out.txt","w"))== NULL) | |
{ | |
printf("Can't open file!"); | |
return 1; | |
} | |
for(int i=0; i<7; i++) | |
{ | |
fprintf(ft,"%s\n%s\n%s\n%s\n%s\n%s\n\n",student[i].a,student[i].b,student[i].c,student[i].d,student[i].e,student[i].f); | |
for(int k=0; k<5;k++) | |
{ | |
if(getc(student[i].f[k])=='5') | |
{ | |
student[i].col++; | |
fprintf(ft,"%s", student[i].col); | |
} | |
} | |
} | |
fclose(ft); | |
system("pause"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a.11 | |
b.khozinova | |
c.sofia | |
d.tagirovna | |
e.1998 | |
f.45455 | |
a.11 | |
b.zolotova | |
c.olga | |
d.semenovna | |
e.1998 | |
f.44455 | |
a.11 | |
b.ivanov | |
c.petr | |
d.pavlovich | |
e.1997 | |
f.34545 | |
a.11 | |
b.petrov | |
c.pavel | |
d.urevich | |
e.1998 | |
f.55545 | |
a.11 | |
b.pavlov | |
c.sergey | |
d.petrovich | |
e.1998 | |
f.45354 | |
a.11 | |
b.kovrov | |
c.maksim | |
d.sergevich | |
e.1998 | |
f.44445 | |
a.11 | |
b.lentan | |
c.igor | |
d.petrovich | |
e.1999 | |
f.44434 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
w |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment