Advertisement
jusohatam

Untitled

Oct 7th, 2020
1,664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     ifstream f;
  10.     f.open("input.txt", ios::in);
  11.     string s, num;
  12.     vector<string> nums;
  13.  
  14.     while (getline(f, s)) {
  15.         for (size_t i = 0; i < s.size(); ++i) {
  16.             if(isdigit(s[i])) {
  17.                 num += s[i];
  18.             } else {
  19.                 if (num != "") {
  20.                     nums.push_back(num);
  21.                 }
  22.                 num = "";
  23.             }
  24.         }
  25.         if (num != "") {
  26.             nums.push_back(num);
  27.         }
  28.         num = "";
  29.     }
  30.     f.close();
  31.     for (string &elem : nums) {
  32.         cout << elem << " ";
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement