add random things
This commit is contained in:
parent
b3cf77045e
commit
767c4c1874
@ -131,14 +131,15 @@
|
|||||||
<ClCompile Include="main.c" />
|
<ClCompile Include="main.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="data.txt" />
|
<Text Include="in12.txt" />
|
||||||
<Text Include="in3.txt" />
|
<Text Include="in3.txt" />
|
||||||
<Text Include="in4.txt" />
|
<Text Include="in4.txt" />
|
||||||
<Text Include="in5.txt" />
|
<Text Include="in5.txt" />
|
||||||
<Text Include="out3.txt" />
|
<Text Include="out3.txt" />
|
||||||
<Text Include="out4.txt" />
|
<Text Include="out4.txt" />
|
||||||
<Text Include="out5.txt" />
|
<Text Include="out5.txt" />
|
||||||
<Text Include="tasks12.txt" />
|
<Text Include="out12.txt" />
|
||||||
|
<Text Include="rand.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
@ -20,10 +20,10 @@
|
|||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="data.txt">
|
<Text Include="in12.txt">
|
||||||
<Filter>Файлы ресурсов</Filter>
|
<Filter>Файлы ресурсов</Filter>
|
||||||
</Text>
|
</Text>
|
||||||
<Text Include="tasks12.txt">
|
<Text Include="out12.txt">
|
||||||
<Filter>Файлы ресурсов</Filter>
|
<Filter>Файлы ресурсов</Filter>
|
||||||
</Text>
|
</Text>
|
||||||
<Text Include="in3.txt">
|
<Text Include="in3.txt">
|
||||||
@ -44,5 +44,8 @@
|
|||||||
<Text Include="out5.txt">
|
<Text Include="out5.txt">
|
||||||
<Filter>Файлы ресурсов</Filter>
|
<Filter>Файлы ресурсов</Filter>
|
||||||
</Text>
|
</Text>
|
||||||
|
<Text Include="rand.txt">
|
||||||
|
<Filter>Файлы ресурсов</Filter>
|
||||||
|
</Text>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -1,5 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
void printarr(int arr[], int len) {
|
void printarr(int arr[], int len) {
|
||||||
printf("[");
|
printf("[");
|
||||||
@ -75,7 +76,7 @@ void save(int arr[], int len, char filename[]) {
|
|||||||
|
|
||||||
void saveRandomArray() {
|
void saveRandomArray() {
|
||||||
int len = 1000;
|
int len = 1000;
|
||||||
char filename[] = "in4.txt";
|
char filename[] = "rand.txt";
|
||||||
|
|
||||||
int* parr;
|
int* parr;
|
||||||
parr = (int*)malloc(sizeof(int) * len);
|
parr = (int*)malloc(sizeof(int) * len);
|
||||||
@ -120,7 +121,7 @@ void dotasks12(int arr[], int len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
save(parr, count, "tasks12.txt");
|
save(parr, count, "out12.txt");
|
||||||
|
|
||||||
free(parr);
|
free(parr);
|
||||||
}
|
}
|
||||||
@ -287,17 +288,46 @@ void task5() {
|
|||||||
free(podd);
|
free(podd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int clip(int n, int lower, int upper) {
|
||||||
|
return max(lower, min(n, upper));
|
||||||
|
}
|
||||||
|
|
||||||
|
void createRandomBinFiles(int n, int minsize, int maxsize) {
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (minsize <= 0 || maxsize >= INT_MAX || maxsize < minsize) {
|
||||||
|
puts("Incorrect minsize or maxsize");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
int size = clip(rand(), minsize, maxsize);
|
||||||
|
|
||||||
|
int* pa = (int*)malloc(size);
|
||||||
|
if (pa == NULL) {
|
||||||
|
puts("Out of memory");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
//saveRandomArray();
|
//saveRandomArray();
|
||||||
|
|
||||||
// task 1
|
// task 1
|
||||||
/*int fixarr[1000];
|
/*int fixarr[1000];
|
||||||
int flen = loadToFixedArray(fixarr, 1000, "data.txt");
|
int flen = loadToFixedArray(fixarr, 1000, "in12.txt");
|
||||||
dotasks12(fixarr, flen);*/
|
dotasks12(fixarr, flen);*/
|
||||||
|
|
||||||
// task 2
|
// task 2
|
||||||
//int* parr;
|
//int* parr;
|
||||||
//int len = load(&parr, "data.txt");
|
//int len = load(&parr, "in12.txt");
|
||||||
//dotasks12(parr, len);
|
//dotasks12(parr, len);
|
||||||
//printarr(parr, len);
|
//printarr(parr, len);
|
||||||
//free(parr);
|
//free(parr);
|
||||||
@ -307,7 +337,7 @@ int main() {
|
|||||||
|
|
||||||
//task4();
|
//task4();
|
||||||
|
|
||||||
task5();
|
//task5();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
2
lab19/lab19/rand.txt
Normal file
2
lab19/lab19/rand.txt
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user