RECOMPILE

来源:互联网 发布:afnetworking上传json 编辑:程序博客网 时间:2024/05/22 05:15

1. Eight Queens Problem

针对书上那个内存泄漏问题

//single linknotestruct linknote{    double data;    linknote*next;};int main(){    linknote*head, *end, *p;    head = end = new linknote;    double x = 0;    while (1)    {        cin >> x;        if (x == -1)break;        p = new linknote;        end->next = p;        p->data = x;        end = p;    }    end->next = NULL;    while (head->next != NULL)    {        linknote*m;        m = head;        head = head->next;        cout << head->data << endl;        delete m;    }    cout << endl;    return 0;}

3. Joseph circle

对于三个就删除的单循环节点
用书上的方法一个接一个直接操作比我写这种判定方式简单

//Link notestruct linknote{    double data;    linknote*next;};int main(){    linknote*head, *end,*p;    head=end = new linknote;    int n;//n persons    cout << "printin n\n";    cin >> n;    p = new linknote;    head->data = 1;    for (int i = 2; i <= n; i++)    {        p = new linknote;        p->data = i;        end->next = p;        end = p;    }    end->next = head;    for (int i = 1; n>0&&i>0; i++)    {        if (i == 2)        {            if (n == 1)            {                cout << "what's left now?\t" << head->data << endl;                break;            }            linknote*tmp;            cout << "the fuckingasshole\t" << head->next->data << endl;            tmp = head->next->next;            delete head->next;            head->next = tmp;            head = head->next;            i = 0;            n--;        }        else            head = head->next;    }    cout << endl;    return 0;}

6. Find Coins

7. Max Size Number

8. Aport Books

原创粉丝点击