Guest User

Untitled

a guest
Apr 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.92 KB | None | 0 0
  1. /*Практическая работа№3. Выполнил: Киселёв Антон, 1081/3
  2. Массивы. Структурные типы.*/
  3. #include<stdio.h>
  4. #include<iostream>
  5. #include<string.h>
  6. #include<vector>
  7. #include"Series.h"
  8. #include<iterator>
  9. #include<locale.h>
  10. using namespace std;
  11. //#define _USE_MATH_DEFINES
  12. int main()
  13. {
  14.     setlocale(LC_ALL, "Russian");
  15. //  if (argc<2) //Проверяем количество аргументов
  16. //     {
  17. //     printf("Ввведите все аргументы");
  18. //     return 0;
  19. //     }
  20. //     else if(argc==2)
  21. //     {
  22. //     argc++;
  23. //     argv[2]="output.txt";
  24. //     }
  25. //    
  26. //    if (strcmp(argv[1],argv[2])==0)
  27. //     {
  28. //     printf("Аргументы должны отличаться");
  29. //     return 0;
  30. //     }
  31. //     if (argc > 3)
  32. //     {
  33. //     printf("Более двух командых параметров, только первые два");
  34. //     }
  35.     FILE *input;//Открываем файл с исходным массивом
  36.     input = fopen("input.txt", "r");
  37.     if (input==NULL)//Производим проверку открытия файла
  38.     {
  39.         printf("Невозможно открыть входной файл\n");
  40.         fclose(input);
  41.         return 1;
  42.     }
  43.  
  44.     FILE *output;//Открываем файл с исходным массивом
  45.     output = fopen("output.txt", "w");
  46.     if (output==NULL)//Производим проверку открытия файла
  47.     {
  48.         printf("Невозможно открыть выходной файл\n");
  49.         fclose(output);
  50.         return 1;
  51.     }
  52.     int retcode=0;
  53.    
  54.  
  55.     vector<int> mass1;//Задаем динамический массив, считывающий строку массива для определения количества столбцов
  56.     int param = 0;
  57.     int ixRow = 0;
  58.     int ixCol = 0;//param-считываемое значение, i,j-индексы
  59.     char temp;//temp-вспомогательная переменная
  60.     int numstolb = 0;
  61.     int numstrok = 0;//Количество столбцов и строк соответственно
  62.     do
  63.     {
  64.         fscanf(input, "%i", &param);//Считываем элемент и помещаем его в массив
  65.         temp = fgetc(input);
  66.         mass1.push_back(param);
  67.         numstolb++;
  68.     }
  69.     while(temp == ' ');
  70.     fclose(input);
  71.    
  72.     //for(ixRow=0; ixRow<mass1.size(); ixRow++) cout<<mass1[ixRow]<<" ";
  73.     //cout<<endl;
  74.     //cout<<numstolb<<" "<<endl;
  75.  
  76.     mass1.clear();
  77.  
  78.     input = fopen("input.txt", "r");
  79.     if (input==NULL)//Производим проверку открытия файла
  80.     {
  81.         printf("Невозможно открыть входной файл\n");
  82.         fclose(input);
  83.         return 1;
  84.     }
  85.    
  86.     vector<vector<int> > mass2;//Задаем динамический массив, в который мы будем помещать строки массива mass3 - получим необходимый двумерный массив
  87.     vector<int> mass3;//Задаем динамический массив, в который мы будем помещать элементы из строки
  88.     do {
  89.         do
  90.         {
  91.             retcode = fscanf(input, "%i", &param);
  92.             if (retcode==EOF)
  93.             {
  94.               printf("Неподходящий тип данных");
  95.               fclose(input);
  96.               return 1;        
  97.             }
  98.             temp = fgetc(input);
  99.             mass3.push_back(param);
  100.             numstolb++;
  101.         }
  102.         while(temp == ' ');
  103.         mass2.push_back(mass3);
  104.         mass3.clear();
  105.         numstolb = 0;
  106.         cout<<"\n";
  107.     }while(temp!=EOF);
  108.     for(ixRow=0; ixRow<mass2.size(); ixRow++)//Выводим считанный массив в файл output
  109.     {
  110.         for(ixCol=0; ixCol<mass2[ixRow].size(); ixCol++)
  111.  
  112.         {
  113.  
  114.  
  115.             cout<<mass2[ixRow][ixCol]<<" ";
  116.             fprintf(output, "%i ", &mass2[ixRow][ixCol]);
  117.  
  118.  
  119.         }
  120.         fprintf(output, "\n");
  121.     }
  122.  
  123.    
  124.     vector<Series> massOfSer;//Задаем динамический массив серий
  125.     Series ser;
  126.  
  127.     obrabotka_po_strokam(mass2, ser, massOfSer);
  128.     obrabotka_po_stolbcam(massOfSer, ser, mass2);
  129.     sortirovkaSeries(massOfSer);
  130.  
  131.     vector<Series> ans; //Задаем динамический массив, служащий ответом к поставленной задаче
  132.  
  133.     answer(ans, massOfSer);
  134.  
  135.  
  136.     mass2.clear();
  137.     mass3.clear();
  138.     return 0;
  139. }
  140. void outOfAnswer(std::vector<Series> ans, FILE *output)//Выводим ответ в выходной файл
  141. {
  142.     int ixCol=0;
  143.     for(ixCol=0; ixCol<ans.size(); ixCol++)
  144.         {
  145.             fprintf(output, "%i ", ans[ixCol].length);
  146.             fprintf(output, "%i ", ans[ixCol].nachStolb);
  147.             fprintf(output, "%i ", ans[ixCol].nachStrok);
  148.             fprintf(output, "%i ", ans[ixCol].StrokOrStolb);
  149.         }
  150. }
Add Comment
Please, Sign In to add comment