Element *dupElement(Element *elm){ Element *ret = newElement(elm->type, NULL); if(ret->type == ET_STRING){ ret->data = (void*)dup((char*)elm->data); }else if(ret->type == ET_INTEGER || ret->type == ET_DECIMAL){ ret->dval = elm->dval; ret->ival = elm->ival; }else if(ret->type == ET_VECTOR){ Vector *v = (Vector*)elm->data; Vector *vnew = newVector(); for(int i=0; i<v->len; ++i){ vectorPushBack(vnew, dupElement(v->data[i])); } ret->data = (void*)vnew; } cloneOps(ret, elm); return ret; }
int main(void) { const int N = 100; int m, n, i, j, isRowBegin, lastInd, cnt, maxCols[N]; Vector v; Comp tmpComp, maxComp; Item tmpItem; Cell cell; for (i = 0; i < N; i++) maxCols[i] = 0; printf("Введите количество строк: "); scanf("%d", &m); printf("Введите количество столбцов: "); scanf("%d", &n); if (m < 1 || m > N) { printf("Количество строк должно быть в диапозоне от 1 до %d\n", N); return 0; } if (n < 1 || n > N) { printf("Количество столбцов должно быть в диапозоне от 1 до %d\n", N); return 0; } vectorCreate(&v, 1); tmpItem.ind = EMPTY; vectorPushBack(&v, tmpItem); for (i = 0; i < m; i++) { isRowBegin = 0; for (j = 0; j < n; j++) { printf("Введите действительную и мнимую части ячейки [%d][%d]: ", i, j); scanf("%lf %lf", &tmpComp.a, &tmpComp.b); if (tmpComp.a == 0.0 && tmpComp.b == 0.0) continue; if (!isRowBegin) { isRowBegin = 1; tmpItem.ind = i; vectorPushBack(&v, tmpItem); } tmpItem.ind = j; vectorPushBack(&v, tmpItem); tmpItem.c = tmpComp; tmpItem.ind = COMP; vectorPushBack(&v, tmpItem); } if (isRowBegin) { tmpItem.ind = EMPTY; vectorPushBack(&v, tmpItem); } } tmpItem.ind = END; vectorPushBack(&v, tmpItem); printf("Обычное представление:\n"); printSourceMatrix(&v, m, n); printf("Внутреннее представление\n"); printInnerMatrix(&v); maxComp.a = 0.0; maxComp.b = 0.0; cell = cellFirst(&v); while (cell.row != END) { if (complexModule(cell.data) > complexModule(maxComp)) maxComp = cell.data; cellNext(&cell); } printf("Максимальное комплексное число по модулю: (%.2lf, %.2lf), модуль равен: %.2lf\n", maxComp.a, maxComp.b, complexModule(maxComp)); if (maxComp.a == 0.0 && maxComp.b == 0) { printf("Делить на него нельзя, так как его модуль равен нулю\n"); return 0; } lastInd = 0; cnt = 0; cell = cellFirst(&v); while (cell.row != END) { if (complexModule(cell.data) == complexModule(maxComp)) { maxCols[cell.col] = 1; lastInd = cell.col; cnt++; } cellNext(&cell); } if (cnt > 1) for (i = lastInd - 1; i >= 0; i--) if (maxCols[i]) { lastInd = i; break; } cell = cellFirst(&v); while (cell.row != END) { if (cell.col == lastInd) { tmpItem = vectorLoad(&v, cell.ind + 1); tmpItem.c = complexDivide(cell.data, maxComp); vectorSave(&v, cell.ind + 1, tmpItem); } cellNext(&cell); } printf("Обычное представление после преобразования:\n"); printSourceMatrix(&v, m, n); printf("Внутреннее представление после преобразования:\n"); printInnerMatrix(&v); vectorDestroy(&v); return 0; }