Advertisement
193030

Prime number + strings

Feb 22nd, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7.     string ns;
  8.  
  9. strRemove(string s)
  10. {
  11.     for(int i =0; i<s.length(); i++){
  12.             if(s.at(i)!=' ')
  13.             {
  14.                 ns+=s.at(i);
  15.             }
  16.  
  17.     }
  18.  
  19. }
  20.  
  21.  
  22. stringSpace(string inputString, int spaceNumber)
  23. {
  24.    int found = -1;
  25.    int lookedSpace = 0;
  26.    int counter = 0;
  27.    do
  28.    {
  29.        found = inputString.find(" ", found+1);
  30.        if(found!=-1)
  31.        {
  32.            lookedSpace = found;
  33.            counter++;
  34.        }
  35.    }
  36.   // while(found<=words.length()-15);
  37.       while(counter<spaceNumber);
  38.       return lookedSpace;
  39.  
  40. }
  41. primeNumberCheck(int n) {
  42.  
  43. int i, m=0, flag=0;
  44.   //cout << "Enter the Number to check Prime: ";
  45.  // cin >> n;
  46.   m=n/2;
  47.   for(i = 2; i <= m; i++)
  48.   {
  49.       if(n % i == 0)
  50.       {
  51.           cout<<"Number is not Prime."<<endl;
  52.           flag=1;
  53.           break;
  54.       }
  55.   }
  56.   if (flag==0)
  57.       cout << "Number is Prime."<<endl;
  58.   return 0;
  59. }
  60.  
  61.  int main()
  62. {
  63.  
  64.    string words = "one two three four five six";
  65.    string word = "zero";
  66.   /* int found = -1;
  67.    int lastSpace = 0;
  68.    int counter = 0;
  69.    do
  70.    {
  71.        found = words.find(" ", found+1);
  72.        if(found!=-1)
  73.        {
  74.            lastSpace = found;
  75.            counter++;
  76.        }
  77.    }
  78.   // while(found<=words.length()-15);
  79.       while(counter<2);
  80.     */
  81.    //words = words.substr(0,found) + " "+ word +words.substr(found);
  82.  
  83.    //words = words.substr(0,lastSpace) + " "+ word +words.substr(lastSpace);
  84.    primeNumberCheck(10);
  85.    int spaceFound = stringSpace(words,1);
  86.   // int spaceFound1 = stringSpace(words,1);
  87.    //int spaceFound2 = stringSpace(words,3);
  88.    words = words.substr(0,spaceFound);
  89.    strRemove(words);
  90.    string outputString = ns; // The string from STR REMOVE
  91.     //words = words.substr(spaceFound1,spaceFound2);
  92.    cout << outputString;
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement