Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <sstream>
- #include <vector>
- using namespace std;
- double stringToDouble(const std::string& s)
- {
- std::istringstream i(s);
- double x;
- if (!(i >> x))
- return 0;
- return x;
- }
- int main ()
- {
- string line;
- ifstream myfile("input.txt");
- getline (myfile,line);
- myfile.close();
- int symbCount = 1;
- for (int i = 0; i < line.length(); i++)
- {
- if (line[i] == ' ')
- symbCount++;
- }
- string* arr = new string[symbCount];
- double* darr = new double[symbCount];
- int cur = 0;
- for (int i = 0; i < line.length(); i++)
- {
- if (line[i] == ' ')
- cur++;
- else
- arr[cur] += line[i];
- }
- vector<int> positions;
- for (int i = 0; i < symbCount; i++)
- {
- darr[i] = stringToDouble(arr[i]);
- if (darr[i] < 0)
- positions.push_back(i);
- }
- ofstream out("output.txt");
- for (int i = 0; i < positions.size(); i++)
- out << positions[i] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement