Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include "pch.h"
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- #include <sstream>
- #include <iterator>
- Point far(Point* arr)
- {
- Point max = arr[0];
- int maxDist = arr[0].x * arr[0].x + arr[0].y * arr[0].y;
- for (int i = 1; i < SIZE; i++)
- {
- int dist = arr[i].x * arr[i].x + arr[i].y * arr[i].y;
- if (dist > maxDist)
- {
- max = arr[i];
- maxDist = dist;
- }
- }
- return max;
- //std::cout « "Max far point is " « max.x « "x " « max.y « "y ; " «std::endl;
- }
- std::vector<int> split(const std::string &s, char delim) {
- std::vector<int> elems;
- std::stringstream ss(s);
- std::string number;
- while (std::getline(ss, number, delim)) {
- elems.push_back(std::stoi(number));
- }
- return elems;
- }
- Point* readFromFile(const char* fileName)
- {
- std::ifstream infile(fileName); // файл из которого читаем (для линукс путь будет выглядеть по другому)
- Point* temp = new Point();
- std::string line;
- while (std::getline(infile, line))
- {
- std::istringstream iss(line);
- std::vector<int> arrTemp = split(line, ';');
- temp->x = arrTemp[0];
- temp->y = arrTemp[1];
- }
- return temp;
- }
- int main()
- {
- Point* arr = readFromFile("C:\test.txt");
- std::cout << "Hello World!\n";
- }
- // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
- // Debug program: F5 or Debug > Start Debugging menu
- // Tips for Getting Started:
- // 1. Use the Solution Explorer window to add/manage files
- // 2. Use the Team Explorer window to connect to source control
- // 3. Use the Output window to see build output and other messages
- // 4. Use the Error List window to view errors
- // 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
- // 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