头像

NeonSean


访客:318

离线:5小时前



NeonSean
7小时前
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplication(ListNode* head) {
        if (!head || !head->next) return head;
        auto dump = new ListNode(-1);
        dump->next = head;
        ListNode* p = dump;
        ListNode* q = p->next;


        while(q) {
            while (q->next && q->val == q->next->val) {
                q = q->next;
            }

            if (p->next == q) {
                p = p->next;
                q = q->next;
            }
            else {
                p->next = q->next;
                q = p->next;
            }
        }

        return dump->next;
    }
};



NeonSean
7小时前
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplication(ListNode* head) {
        if (!head || !head->next) return head;
        auto dump = new ListNode(-1);
        dump->next = head;
        ListNode* p = dump;
        ListNode* q = p->next;


        while(q) {
            while (q->next && q->val == q->next->val) {
                q = q->next;
            }

            if (p->next == q) {
                p = p->next;
                q = q->next;
            }
            else {
                p->next = q->next;
                q = p->next;
            }
        }

        return dump->next;
    }
};


活动打卡代码 AcWing 35. 反转链表

NeonSean
8小时前
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {

        if (!head || !head->next) return head;

        ListNode* p = head;
        ListNode* q = head->next;

        while (q) {
            auto o = q->next;
            q->next = p;
            p = q, q = o;
        }
        head->next = NULL;
        return p;
    }
};



NeonSean
15小时前
#include <cstdio>
#include <cmath>

int main() {
    double a, b, c;
    scanf("%lf%lf%lf", &a, &b, &c);
    double d = b * b - 4 * a * c;
    if (d < 0 || a == 0) printf("Impossivel calcular");
    else if (d > 0) {
        double x, y;
        x = (- b + sqrt(d) ) / (2 * a);
        y = (- b - sqrt(d) ) / (2 * a);
        printf("R1 = %.5lf\n", x);
        printf("R2 = %.5lf\n", y);
    }
    return 0;
}


活动打卡代码 AcWing 618. 燃料消耗

#include <cstdio>

int main() {
    int t, v;
    scanf("%d%d", &t, &v);
    printf("%.3lf", (double) t * v / 12);
    return 0;
}


活动打卡代码 AcWing 612. 球的体积

#include <cstdio>

const double pi = 3.14159;

int main() {
    int r;
    scanf("%d", &r);
    printf("VOLUME = %.3lf", (double)(4 / 3.0) * pi * r * r* r);
    return 0;
}


活动打卡代码 AcWing 672. 税

#include <cstdio>

int main() {
    double a;
    scanf("%lf", &a);
    double sum = 0;

    if (a > 2000) {
        double b = 3000;
        if ( a  <  b)  b = a;
        sum += (b - 2000) * 0.08;
    }

    if (a > 3000) {
        double b = 4500;
        if ( a < b) b = a;
        sum += (b - 3000) * 0.18;
    }

    if (a > 4500) {
        sum += (a - 4500) * 0.28;
    }

    if (sum == 0) printf("Isento\n");
    else printf("R$ %.2lf", sum);

    return 0;
}



#include <iostream>

using namespace std;

int main() {
    int n, a[1000];
    cin >> n;
    int x, y;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (x > a[i]) {
            x = a[i];
            y = i;
        }
    }
    cout << "Minimum value: " << x << endl;
    cout << "Position: " << y << endl;
    return 0;
}



#include <iostream>

using namespace std;

int min(int a, int b) {
    if (a > b)
        return b;
    else return a;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else return b;
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(a, min(b, c)) << endl;
    cout << a + b + c - min(a, min(b, c)) - max(a, max(b, c)) << endl;
    cout << max(a, max(b, c)) << endl;
    cout << endl;
    cout << a << endl;
    cout << b << endl;
    cout << c << endl;
    return 0;
}


活动打卡代码 AcWing 663. 简单排序

#include <iostream>

using namespace std;

int min(int a, int b) {
    if (a > b)
        return b;
    else return a;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else return b;
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(a, min(b, c)) << endl;
    cout << a + b + c - min(a, min(b, c)) - max(a, max(b, c)) << endl;
    cout << max(a, max(b, c)) << endl;
    cout << endl;
    cout << a << endl;
    cout << b << endl;
    cout << c << endl;
    return 0;
}