Skocz do zawartości

Recommended Posts

  • 2 weeks later...
  • 5 months later...
Napisano

Stare to ale może dorzucę odpowiedź dla potomnych  / leniwych
 

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <sstream>

int main() {
    std::ifstream inputFile("input.csv");
    std::ofstream outputFile("output.csv");

    if (!inputFile.is_open() || !outputFile.is_open()) {
        std::cout << "Cannot open file!" << std::endl;
        return 1;
    }

    std::vector<int> numbers;
    std::string line, value;

    while (std::getline(inputFile, line)) {
        std::stringstream ss(line);
        while (std::getline(ss, value, ',')) {
            numbers.push_back(std::stoi(value));
        }
    }

    std::sort(numbers.begin(), numbers.end());

    for (size_t i = 0; i < numbers.size(); ++i) {
        outputFile << numbers[i];
        if (i < numbers.size() - 1) {
            outputFile << ",";
        }
    }

    inputFile.close();
    outputFile.close();

    std::cout << "Numbers sorted and saved in output.csv" << std::endl;

    return 0;
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gość
Odpowiedz...

×   Wkleiłeś zawartość bez formatowania.   Usuń formatowanie

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Utwórz nowe...