Imran1107048

String Splitting using STL

May 8th, 2022 (edited)
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string split(string s, int n)
  5. {
  6.     string t = "";
  7.     for(int i=n;i<s.size();i++){
  8.         t += s[i];
  9.     }
  10.     return t;
  11. }
  12.  
  13. int main()
  14. {
  15.     vector<string>words = {"ALFA", "BRAVO", "GOLF", "HOTEL", "INDIA", "JULIETT", "KILO", "LIMA", "X-RAY", "YANKEE", "ZULU", "MIKE", "NOVEMBER", "UNIFORM", "OSCAR",
  16.     "PAPA", "QUEBEC", "ROMEO", "SIERRA", "TANGO", "VICTOR", "WHISKEY", "CHARLIE", "DELTA", "ECHO", "FOXTROT"};
  17.  
  18.     sort(words.begin(), words.end());
  19.     cout << "After Sorting: \n";
  20.     for(string i:words)
  21.         cout << i << endl;
  22.  
  23.     cout << "Enter a number from 1 to 9: ";
  24.     int n;
  25.     cin >> n;
  26.     n--;
  27.     vector<string>splitted_strings;
  28.     for(string i:words){
  29.         string t = i;
  30.         splitted_strings.push_back(split(t, n));
  31.     }
  32.     sort(splitted_strings.begin(), splitted_strings.end());
  33.     cout << "After splitting from the given index.\n";
  34.     for(string i:splitted_strings)
  35.         cout << i << endl;
  36. }
  37.  
Add Comment
Please, Sign In to add comment