204 lines
3.1 KiB
C
204 lines
3.1 KiB
C
|
#include <stdio.h>
|
|||
|
#include <Windows.h>
|
|||
|
|
|||
|
void srar(), Load();
|
|||
|
void Psrar(), PLoad(int);
|
|||
|
void Psrar3();
|
|||
|
void Z4();
|
|||
|
|
|||
|
int arr[1000];
|
|||
|
int* parr;
|
|||
|
int n;
|
|||
|
|
|||
|
int main1() {
|
|||
|
SetConsoleCP(1251);
|
|||
|
SetConsoleOutputCP(1251);
|
|||
|
|
|||
|
Load();
|
|||
|
srar();
|
|||
|
|
|||
|
PLoad(0);
|
|||
|
Psrar();
|
|||
|
free(parr);
|
|||
|
|
|||
|
PLoad(1);
|
|||
|
Psrar3();
|
|||
|
free(parr);
|
|||
|
|
|||
|
PLoad(2);
|
|||
|
Z4();
|
|||
|
free(parr);
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
void Load() {
|
|||
|
FILE* fin = fopen("D:\\university\\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\lab\\Temp\\19-20\\in1.txt", "rt");
|
|||
|
if (fin == NULL) {
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
fscanf_s(fin, "%d", &n);
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
fscanf_s(fin, "%d", &arr[i]);
|
|||
|
}
|
|||
|
|
|||
|
fclose(fin);
|
|||
|
}
|
|||
|
|
|||
|
void srar() {
|
|||
|
float sa = 0;
|
|||
|
float s = 0;
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
s += arr[i];
|
|||
|
}
|
|||
|
sa = s / n;
|
|||
|
|
|||
|
|
|||
|
int m = 0;
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
if (arr[i] > sa) {
|
|||
|
m++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
FILE* fout = fopen("D:\\university\\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\lab\\Temp\\19-20\\out\\out1.txt", "wt");
|
|||
|
if (fout == NULL) {
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
fprintf(fout, "%d\n", m);
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
if (arr[i] > sa) {
|
|||
|
fprintf(fout, "%d ", arr[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
fclose(fout);
|
|||
|
}
|
|||
|
|
|||
|
void PLoad(int action) {
|
|||
|
FILE* fin = NULL;
|
|||
|
if (action == 0) {
|
|||
|
fopen_s(&fin, "D:\\university\\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\lab\\Temp\\19-20\\in2.txt", "rt");
|
|||
|
}
|
|||
|
else if (action == 1) {
|
|||
|
fopen_s(&fin, "D:\\university\\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\lab\\Temp\\19-20\\in3.txt", "rt");
|
|||
|
}
|
|||
|
else if (action == 2) {
|
|||
|
fopen_s(&fin, "D:\\university\\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\lab\\Temp\\19-20\\in4.txt", "rt");
|
|||
|
}
|
|||
|
|
|||
|
if (fin == NULL) {
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
fscanf_s(fin, "%d", &n);
|
|||
|
parr = (int*)malloc(sizeof(int) * n);
|
|||
|
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
fscanf_s(fin, "%d", &parr[i]);
|
|||
|
}
|
|||
|
|
|||
|
fclose(fin);
|
|||
|
}
|
|||
|
|
|||
|
void Psrar() {
|
|||
|
float sa = 0;
|
|||
|
float s = 0;
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
s += parr[i];
|
|||
|
}
|
|||
|
sa = s / n;
|
|||
|
|
|||
|
int m = 0;
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
if (parr[i] > sa) {
|
|||
|
m++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
FILE* fout = fopen("D:\\university\\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\lab\\Temp\\19-20\\out\\out2.txt", "wt");
|
|||
|
if (fout == NULL) {
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
fprintf(fout, "%d\n", m);
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
if (parr[i] > sa) {
|
|||
|
fprintf(fout, "%d ", parr[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
fclose(fout);
|
|||
|
}
|
|||
|
|
|||
|
void Psrar3() {
|
|||
|
float sa = 0;
|
|||
|
float s = 0;
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
s += parr[i];
|
|||
|
}
|
|||
|
sa = s / n;
|
|||
|
|
|||
|
int m = 0;
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
if (parr[i] < sa && parr[i] > 0) {
|
|||
|
m++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
FILE* fout = fopen("D:\\university\\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\lab\\Temp\\19-20\\out\\out3.txt", "wt");
|
|||
|
if (fout == NULL) {
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
fprintf(fout, "%d\n", m);
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
if (parr[i] < sa && parr[i] > 0) {
|
|||
|
fprintf(fout, "%d ", parr[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
fclose(fout);
|
|||
|
}
|
|||
|
|
|||
|
void Z4() {
|
|||
|
float max = parr[0];
|
|||
|
for (int i = 1; i < n; i++) {
|
|||
|
if (parr[i] > max) {
|
|||
|
max = parr[i];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
float more_then = max*2/3;
|
|||
|
|
|||
|
int k = 0;
|
|||
|
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
if (parr[i] >= more_then) {
|
|||
|
k++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
FILE* fout = fopen("D:\\university\\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\lab\\Temp\\19-20\\out\\out4.txt", "wt");
|
|||
|
if (fout == NULL) {
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
fprintf(fout, "%d\n", k);
|
|||
|
for (int i = 0; i < n; i++) {
|
|||
|
if (parr[i] >= more_then) {
|
|||
|
fprintf(fout, "%d ", parr[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
fclose(fout);
|
|||
|
}
|