193030

While, sstream, 2 vectors[ ] WITH INT

Apr 4th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <string.h>
  4. #include <vector>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.  
  9. long sstoi(const char *s) // custom stoi function
  10. {
  11.     long i;
  12.     i = 0;
  13.     while(*s >= '0' && *s <= '9')
  14.     {
  15.         i = i * 10 + (*s - '0');
  16.         s++;
  17.     }
  18.     return i;
  19. }
  20.  
  21. int main()
  22. {
  23.     string newString, input;
  24.     vector <int> nums(1);
  25.     vector <int> nums2(1);
  26.     vector <int> nums3(1);
  27.     int k =0;
  28.     while(cin>>k)
  29.     {
  30.         cin.ignore();
  31.     getline(cin, input);
  32.     stringstream stream;
  33.     stream.str(input);
  34.     stream.clear();
  35.     while(stream >> newString)
  36.     {
  37.         nums.push_back(sstoi(newString.c_str()));
  38.     }
  39.  
  40.  
  41.  
  42.     getline(cin, input);
  43.     stream.str(input);
  44.     stream.clear();
  45.     while(stream >> newString)
  46.     {
  47.         nums2.push_back(sstoi(newString.c_str()));
  48.  
  49.     }
  50.  
  51.     getline(cin, input);
  52.     stream.str(input);
  53.     stream.clear();
  54.     while(stream >> newString)
  55.     {
  56.         nums3.push_back(sstoi(newString.c_str()));
  57.  
  58.     }
  59.     for(int i =1; i< nums.size(); i++)
  60.  
  61.     {
  62.         cout << "nums 1 " << nums[i] << endl;
  63.     }
  64.     for(int i =1; i< nums2.size(); i++)
  65.  
  66.     {
  67.         cout <<"nums 2 " << nums2[i] << endl;
  68.     }
  69.     for(int i =1; i< nums3.size(); i++)
  70.  
  71.     {
  72.         cout <<"nums 3 " << nums3[i] << endl;
  73.     }
  74.     cout << "K e: " << k << endl;
  75.     }
  76.  
  77.  
  78.  
  79.  
  80. }
Add Comment
Please, Sign In to add comment