两数之和打印下标

#include <iostream> 
#include <vector>

using namespace std;

class twoand
{
public:
    vector<int> t1;
    twoand()
    {
        cout << "hello word!" << endl;
    }
    vector<int> towsum()
    {
        vector<int> v1;
        int s = size(test);
        cout << s << endl;
        for (int i = 0; i < s; i++)
        {
            for (int j = 0; j < i + 1; j++)
            {
                if (test[i] + test[j] == target)
                    cout << i<<"\t" << j << endl;
            }
        }
        return v1;
    }

private:
    int test[5] = { 2,6,9,5 };
    int target = 11;
};
    int main(void)
    {
        twoand a;
           a.towsum();
        cin.get();

        return 0;
    }

 

posted @ 2022-01-14 16:40  乐吴  阅读(36)  评论(0编辑  收藏  举报