Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. // ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <fstream>
  8. #include <vector>
  9. #include <algorithm>
  10. #include <sstream>
  11. #include <iterator>
  12.  
  13.  
  14. Point far(Point* arr)
  15. {
  16.     Point max = arr[0];
  17.     int maxDist = arr[0].x * arr[0].x + arr[0].y * arr[0].y;
  18.     for (int i = 1; i < SIZE; i++)
  19.     {
  20.         int dist = arr[i].x * arr[i].x + arr[i].y * arr[i].y;
  21.         if (dist > maxDist)
  22.         {
  23.             max = arr[i];
  24.             maxDist = dist;
  25.         }
  26.     }
  27.  
  28.     return max;
  29.     //std::cout « "Max far point is " « max.x « "x " « max.y « "y ; " «std::endl;
  30. }
  31.  
  32. std::vector<int> split(const std::string &s, char delim) {
  33.     std::vector<int> elems;
  34.     std::stringstream ss(s);
  35.     std::string number;
  36.     while (std::getline(ss, number, delim)) {
  37.         elems.push_back(std::stoi(number));
  38.     }
  39.     return elems;
  40. }
  41.  
  42. Point* readFromFile(const char* fileName)
  43. {
  44.     std::ifstream infile(fileName); // файл из которого читаем (для линукс путь будет выглядеть по другому)
  45.    
  46.     Point* temp = new Point();
  47.     std::string line;
  48.     while (std::getline(infile, line))
  49.     {
  50.         std::istringstream iss(line);
  51.         std::vector<int> arrTemp = split(line, ';');
  52.        
  53.         temp->x = arrTemp[0];
  54.         temp->y = arrTemp[1];
  55.     }
  56.  
  57.     return  temp;
  58. }
  59.  
  60.  
  61.  
  62. int main()
  63. {
  64.     Point* arr = readFromFile("C:\test.txt");
  65.     std::cout << "Hello World!\n";
  66. }
  67.  
  68. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  69. // Debug program: F5 or Debug > Start Debugging menu
  70.  
  71. // Tips for Getting Started:
  72. //   1. Use the Solution Explorer window to add/manage files
  73. //   2. Use the Team Explorer window to connect to source control
  74. //   3. Use the Output window to see build output and other messages
  75. //   4. Use the Error List window to view errors
  76. //   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
  77. //   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement