240 lines
4.0 KiB
C
240 lines
4.0 KiB
C
#include "TwoDimentionalArray.h"
|
|
|
|
int arr[MAX_LENGTH][MAX_LENGTH];
|
|
int width, height;
|
|
|
|
void inputdem() {
|
|
printf("height ");
|
|
scanf_s("%d", &height);
|
|
|
|
printf("width ");
|
|
scanf_s("%d", &width);
|
|
}
|
|
|
|
void randomEl() {
|
|
if (width == 0 || height == 0) inputdem();
|
|
for (int i = 0; i < height; i++) {
|
|
for (int j = 0; j < width; j++) {
|
|
arr[i][j] = rand() % 10 + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
void iX10j() {
|
|
if (width == 0 || height == 0) inputdem();
|
|
for (int i = 0; i < height; i++) {
|
|
for (int j = 0; j < width; j++) {
|
|
arr[i][j] = (i+1)*10+j+1;
|
|
}
|
|
}
|
|
}
|
|
|
|
void setZero() {
|
|
if (width == 0 || height == 0) inputdem();
|
|
for (int i = 0; i < height; i++) {
|
|
for (int j = 0; j < width; j++) {
|
|
arr[i][j] = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
void inputArr() {
|
|
inputdem();
|
|
for (int i = 0; i < height; i++) {
|
|
for (int j = 0; j < width; j++) {
|
|
scanf_s("%d", &arr[i][j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
void oddX10() {
|
|
for (int i = 0; i < height; i++) {
|
|
for (int j = 0; j < width; j++) {
|
|
if (arr[i][j] % 2 != 0) {
|
|
arr[i][j] = arr[i][j] * 10;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void del10() {
|
|
for (int i = 0; i < height; i++) {
|
|
for (int j = 0; j < width; j++) {
|
|
if (arr[i][j] % 10 == 0) {
|
|
arr[i][j] = arr[i][j] / 10;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void save() {
|
|
FILE* fout = fopen("D:\\university\\ÎÀÈÏ\\lab\\Temp\\test.txt", "wt");
|
|
|
|
if (fout == NULL) {
|
|
printf("Âûõîäíîé ôàéë íå ñîçäàëñÿ");
|
|
return;
|
|
}
|
|
|
|
fprintf(fout, "%d ", height);
|
|
fprintf(fout, "%d\n", width);
|
|
for (int i = 0; i < height; i++) {
|
|
for (int j = 0; j < width; j++) {
|
|
fprintf(fout, "%d ", arr[i][j]);
|
|
}
|
|
fprintf(fout, "\n");
|
|
}
|
|
|
|
printf("ñîõðàíåíèå\n");
|
|
|
|
fclose(fout);
|
|
}
|
|
|
|
void load() {
|
|
FILE* fin = fopen("D:\\university\\ÎÀÈÏ\\lab\\Temp\\test.txt", "rt");
|
|
|
|
if (fin == NULL) {
|
|
printf("Âûõîäíîé ôàéë íå íàéäåí");
|
|
return;
|
|
}
|
|
|
|
fscanf_s(fin, "%d", &height);
|
|
fscanf_s(fin, "%d", &width);
|
|
for (int i = 0; i < height; i++) {
|
|
for (int j = 0; j < width; j++) {
|
|
fscanf_s(fin, "%d", &arr[i][j]);
|
|
}
|
|
}
|
|
|
|
printf("çàãðóçêà\n");
|
|
|
|
fclose(fin);
|
|
}
|
|
|
|
void dublicateCol() {
|
|
int index;
|
|
printf("index ");
|
|
scanf_s("%d", &index);
|
|
for (int i = width; i > index; i--) {
|
|
for (int j = 0; j < height; j++) {
|
|
arr[j][i] = arr[j][i - 1];
|
|
}
|
|
}
|
|
width += 1;
|
|
}
|
|
|
|
void DeleteRow() {
|
|
int index;
|
|
printf("index ");
|
|
scanf_s("%d", &index);
|
|
height -= 1;
|
|
for (int i = index; i < height; i++) {
|
|
for (int j = 0; j < width; j++) {
|
|
arr[i][j] = arr[i + 1][j];
|
|
}
|
|
}
|
|
}
|
|
|
|
void zeroWhereRepeat() {
|
|
for (int j = 0; j < width; j++) {
|
|
|
|
bool DO = false;
|
|
|
|
for (int i = 0; i < height - 1; i++) {
|
|
for (int ii = i + 1; ii < height; ii++) {
|
|
if (arr[i][j] == arr[ii][j]) {
|
|
DO = true;
|
|
goto end;
|
|
}
|
|
}
|
|
}
|
|
end:
|
|
if (DO) {
|
|
for (int i = 0; i < height; i++) {
|
|
arr[i][j] = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void printArr() {
|
|
for (int i = 0; i < height; i++) {
|
|
for (int j = 0; j < width; j++) {
|
|
printf("%3d ", arr[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
}
|
|
|
|
void menuText() {
|
|
printf("\n\n");
|
|
if (height != 0) {
|
|
printf("äëèííà: %d\n", height);
|
|
printArr(arr, width, height);
|
|
}
|
|
printf("--------------\n");
|
|
printf("âûáåðèòå íóæíóþ âàì îïåðàöèÿ:\n");
|
|
printf("1) Çàïîëíèòü çíà÷åíèÿìè i * 10 + j\n");
|
|
printf("2) Çàïîëíèòü 0\n");
|
|
printf("3) Çàïîëíèòü ñëó÷àéíûìè\n");
|
|
printf("4) Âñå íå÷åòíûå õ10\n");
|
|
printf("5) Âñå % 10 õ1del10\n");
|
|
printf("6) Ìàññèâ ñ êëàâèàòóðû\n");
|
|
printf("71) Ñîõðàíèòü\n");
|
|
printf("72) Çàãðóçèòü\n");
|
|
printf("8) 0 ãäå ïîñòîðÿåòñÿ\n");
|
|
printf("9) Äóáëèðîâàòü êîëîíêó\n");
|
|
printf("10) Óäàëèòü ñòðîêó\n");
|
|
printf("\n");
|
|
printf("-1) âûéòè\n");
|
|
printf("âûáðàííàÿ îïåðàöèÿ >>> ");
|
|
}
|
|
|
|
void startProg() {
|
|
|
|
srand(time(NULL));
|
|
|
|
int ans;
|
|
do {
|
|
menuText();
|
|
scanf_s("%d", &ans);
|
|
|
|
switch (ans)
|
|
{
|
|
case 1:
|
|
iX10j();
|
|
break;
|
|
case 2:
|
|
setZero();
|
|
break;
|
|
case 3:
|
|
randomEl();
|
|
break;
|
|
case 4:
|
|
oddX10();
|
|
break;
|
|
case 5:
|
|
del10();
|
|
break;
|
|
case 6:
|
|
inputArr();
|
|
break;
|
|
case 71:
|
|
save();
|
|
break;
|
|
case 72:
|
|
load();
|
|
break;
|
|
case 8:
|
|
zeroWhereRepeat();
|
|
break;
|
|
case 9:
|
|
dublicateCol();
|
|
break;
|
|
case 10:
|
|
DeleteRow();
|
|
default:
|
|
break;
|
|
}
|
|
} while (ans != -1);
|
|
} |