-1

Below is how the solution should look like.


Enter Y : 239847239
Enter X : 847
X is substring of Y

Enter Y : 239847239
Enter X : 3923
X is subsequence of Y

Enter Y : 239847239
Enter X : 489
X is neither substring nor subsequence of Y


and below is my crude attempt at making the code:

int main() 
{

    cout << "Enter Y: ";
    vector <int> Y;
    int Y_number;
    cin >> Y_number;

    cout << "Enter X: ";
    vector <int> X;
    cin >> X;

    if (Y > X)
    {
        for(int i = 0; i < Y.size(); i++)
        {
            Y.push_back(Y_number);
            if (Y.size(i) == X.size(i))
            {

            }
        }
    }
    else
    {
        cout << "X is neither substring nor subsequence of Y";
    }
}
Casey
  • 10,297
  • 11
  • 59
  • 88
  • Please format properly – Enamul Hassan Sep 26 '15 at 06:23
  • There are a bunch of things here and you don't even describe a specific problem (which is also why this question is probably being closed). However, here's some advise: Firstly, separate input from the tests for the two properties by simply using functions. One function `bool is_substring(string const& s, string const& sub)` and another `bool is_subsequence(string const& s, string const& sub)`, who's implementation I'll leave to you. Splitting these off means you now have three (two functions plus the glue code connecting them) smaller problems, which you can each solve separately. – Ulrich Eckhardt Sep 26 '15 at 07:04

1 Answers1

0

Maybe this is what you want:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string Y, X, YY;
    cout << "Enter Y: ";
    cin >> Y;
    cout << "Enter X: ";
    cin >> X;
    YY = Y + Y;

    if (std::string::npos != Y.find(X)) {
        cout << "X is substring of Y" << endl;
    } else if (std::string::npos != YY.find(X)) {
        cout << "X is subsequence of Y" << endl;
    } else {
        cout << "X is neither substring nor subsequence of Y" << endl;
    }
    return 0;
}

UPDATE: at least it generates the same results as your description.

mkvoya
  • 156
  • 1
  • 4