Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Практическая работа№3. Выполнил: Киселёв Антон, 1081/3
- Массивы. Структурные типы.*/
- #include<stdio.h>
- #include<iostream>
- #include<string.h>
- #include<vector>
- #include"Series.h"
- #include<iterator>
- #include<locale.h>
- using namespace std;
- //#define _USE_MATH_DEFINES
- int main()
- {
- setlocale(LC_ALL, "Russian");
- // if (argc<2) //Проверяем количество аргументов
- // {
- // printf("Ввведите все аргументы");
- // return 0;
- // }
- // else if(argc==2)
- // {
- // argc++;
- // argv[2]="output.txt";
- // }
- //
- // if (strcmp(argv[1],argv[2])==0)
- // {
- // printf("Аргументы должны отличаться");
- // return 0;
- // }
- // if (argc > 3)
- // {
- // printf("Более двух командых параметров, только первые два");
- // }
- FILE *input;//Открываем файл с исходным массивом
- input = fopen("input.txt", "r");
- if (input==NULL)//Производим проверку открытия файла
- {
- printf("Невозможно открыть входной файл\n");
- fclose(input);
- return 1;
- }
- FILE *output;//Открываем файл с исходным массивом
- output = fopen("output.txt", "w");
- if (output==NULL)//Производим проверку открытия файла
- {
- printf("Невозможно открыть выходной файл\n");
- fclose(output);
- return 1;
- }
- int retcode=0;
- vector<int> mass1;//Задаем динамический массив, считывающий строку массива для определения количества столбцов
- int param = 0;
- int ixRow = 0;
- int ixCol = 0;//param-считываемое значение, i,j-индексы
- char temp;//temp-вспомогательная переменная
- int numstolb = 0;
- int numstrok = 0;//Количество столбцов и строк соответственно
- do
- {
- fscanf(input, "%i", ¶m);//Считываем элемент и помещаем его в массив
- temp = fgetc(input);
- mass1.push_back(param);
- numstolb++;
- }
- while(temp == ' ');
- fclose(input);
- //for(ixRow=0; ixRow<mass1.size(); ixRow++) cout<<mass1[ixRow]<<" ";
- //cout<<endl;
- //cout<<numstolb<<" "<<endl;
- mass1.clear();
- input = fopen("input.txt", "r");
- if (input==NULL)//Производим проверку открытия файла
- {
- printf("Невозможно открыть входной файл\n");
- fclose(input);
- return 1;
- }
- vector<vector<int> > mass2;//Задаем динамический массив, в который мы будем помещать строки массива mass3 - получим необходимый двумерный массив
- vector<int> mass3;//Задаем динамический массив, в который мы будем помещать элементы из строки
- do {
- do
- {
- retcode = fscanf(input, "%i", ¶m);
- if (retcode==EOF)
- {
- printf("Неподходящий тип данных");
- fclose(input);
- return 1;
- }
- temp = fgetc(input);
- mass3.push_back(param);
- numstolb++;
- }
- while(temp == ' ');
- mass2.push_back(mass3);
- mass3.clear();
- numstolb = 0;
- cout<<"\n";
- }while(temp!=EOF);
- for(ixRow=0; ixRow<mass2.size(); ixRow++)//Выводим считанный массив в файл output
- {
- for(ixCol=0; ixCol<mass2[ixRow].size(); ixCol++)
- {
- cout<<mass2[ixRow][ixCol]<<" ";
- fprintf(output, "%i ", &mass2[ixRow][ixCol]);
- }
- fprintf(output, "\n");
- }
- vector<Series> massOfSer;//Задаем динамический массив серий
- Series ser;
- obrabotka_po_strokam(mass2, ser, massOfSer);
- obrabotka_po_stolbcam(massOfSer, ser, mass2);
- sortirovkaSeries(massOfSer);
- vector<Series> ans; //Задаем динамический массив, служащий ответом к поставленной задаче
- answer(ans, massOfSer);
- mass2.clear();
- mass3.clear();
- return 0;
- }
- void outOfAnswer(std::vector<Series> ans, FILE *output)//Выводим ответ в выходной файл
- {
- int ixCol=0;
- for(ixCol=0; ixCol<ans.size(); ixCol++)
- {
- fprintf(output, "%i ", ans[ixCol].length);
- fprintf(output, "%i ", ans[ixCol].nachStolb);
- fprintf(output, "%i ", ans[ixCol].nachStrok);
- fprintf(output, "%i ", ans[ixCol].StrokOrStolb);
- }
- }
Add Comment
Please, Sign In to add comment