Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // 2
- //
- // Created by Kuba Sipika on 12/11/2019.
- // Copyright © 2019 Kuba Sipika. All rights reserved.
- //
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <sstream>
- #include <cassert>
- #define assertm(exp, msg) assert(((void)msg, exp))
- struct DescriptionLine {
- std::vector<int> wspolrzedne;
- double wspolczynnik;
- };
- struct Description {
- int k = 0;
- int n = 0;
- std::vector<DescriptionLine> descriptionLines;
- };
- struct InputLine {
- std::vector<double> wsp;
- };
- struct Input {
- std::vector<InputLine> inputLines;
- };
- Description readDescription(std::string fileName) {
- Description tempDesc;
- bool first_red = false;
- std::ifstream input(fileName);
- for( std::string line; getline( input, line ); )
- {
- std::istringstream stream(line);
- std::vector<std::string> results(std::istream_iterator<std::string>{stream},std::istream_iterator<std::string>());
- if(!first_red) {
- assertm(results.size() == 2, "FIRST DESC LINE HAS TO BE 2 NUMBERS!");
- tempDesc.k = atoi(results[0].c_str());
- tempDesc.n = atoi(results[1].c_str());
- first_red = true;
- continue;
- }
- assertm(results.size() == tempDesc.n + 1 , "DescLine error!");
- DescriptionLine tempDescLine;
- for (auto i = 0; i<results.size()-1; i++) {
- tempDescLine.wspolrzedne.push_back(atoi(results[i].c_str()));
- }
- tempDescLine.wspolczynnik = atof(results[results.size()-1].c_str());
- tempDesc.descriptionLines.push_back(tempDescLine);
- }
- return tempDesc;
- }
- Input readInput() {
- Input tempInput;
- for( std::string line; getline( std::cin, line ); )
- {
- std::istringstream stream(line);
- std::vector<std::string> results(std::istream_iterator<std::string>{stream},std::istream_iterator<std::string>());
- InputLine tempInputLine;
- for (auto s : results) {
- tempInputLine.wsp.push_back(atof(s.c_str()));
- }
- tempInput.inputLines.push_back(tempInputLine);
- }
- return tempInput;
- }
- void writeOutput(std::vector<double> results) {
- for (auto r : results) {
- std::cout << r << std::endl;
- }
- }
- int main(int argc, const char * argv[]) {
- assertm(argc == 3, "Unexpected args! error!");
- std::string descriptionFileName;
- for (int i = 0 ; i < argc; i++) {
- auto arg = std::string(argv[i]);
- if(arg.compare("-d") == 0) { descriptionFileName = std::string(argv[i+1]); continue; }
- }
- auto description = readDescription(descriptionFileName);
- auto input = readInput();
- auto result = {-6.0, 1.02, 18.0, 27.0, 22.0};
- writeOutput(result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement