整数模式

时间:2015-09-26 06:07:02

标签: c++ substring subset subsequence

以下是解决方案的外观。

输入Y:239847239
输入X:847
X是Y

的子串

输入Y:239847239
输入X:3923
X是Y

的后续序列

输入Y:239847239
输入X:489
X既不是Y的子串也不是Y

的子序列

以下是我制作代码的粗略尝试:

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";
    }
}

1 个答案:

答案 0 :(得分:0)

也许这就是你想要的:

#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;
}

更新:至少它会生成与您的描述相同的结果。