1025

问题严重!

#include
#include
#include
#include


using namespace std;

class list_creat
{
public:
    list_creat(istream &in) { in >> address >> data >> next; }
    string& get_address() { return address; }
    long long& get_data() { return data; }
    string& get_next() { return next; }

private:
    long long data = 0;
    string address;
    string next;
};

class list_result
{
public:
    list_result(vector &l) :list_info(l) {};
    void sort(string address, unsigned n, unsigned k) { list_default(address); sort_by_format(n, k); };
    friend ostream &operator<<(ostream &os,const list_result &rhs);

private:
    vector list_info;
    void sort_by_format(unsigned n,unsigned k);
    void list_default(string cur_add);
};

void list_result::list_default(string cur_add)
{
    vector tmp;
    while (true)
    {
        for (auto &r : list_info)
        {
            if (cur_add == r.get_address())
            {
                tmp.push_back(r);
                cur_add = r.get_next();
                break;
            }
        }
        if (cur_add == "-1")
            break;
    }
    *this = tmp;
}
void list_result::sort_by_format(unsigned n,unsigned k)
{
    unsigned count = n / k;
    for (unsigned i = 0; i < count; ++i)
    {
        for (unsigned j = 0; j < k/2; ++j)
        {
            auto tmp = list_info[j + i*k];
            list_info[j + i*k] = list_info[i*k + k - j - 1];
            list_info[i*k + k - j - 1] = tmp;
        }
    }
    for (unsigned i=0;i> first_add >> n >> k;

    vector in_list;
    for (unsigned i = 0; i < n; ++i)
    {
        in_list.push_back(list_creat(cin));
    }
    
    list_result result(in_list);
    result.sort(first_add, n, k);
    cout << result;
    
    cout << endl;
    system("pause");
    return 0;
}

你可能感兴趣的:(1025)