头像

Weiiii.

HUST




离线:1天前


最近来访(10)
用户头像
Cospine
用户头像
товарищи_0
用户头像
noshadow
用户头像
Aro
用户头像
之一_0
用户头像
前缀自动机
用户头像
自己身上找问题
用户头像
mbj
用户头像
Nana_4


Weiiii.
8天前
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~


class MyQueue {
public:
    /** Initialize your data structure here. */
    stack<int> stk,cache;

    MyQueue() {

    }

    /** Push element x to the back of queue. */
    void push(int x) {
        stk.push(x);
    }


    void copy(stack<int> &a,stack<int> &b)
    {
        while(a.size())
        {
            b.push(a.top());
            a.pop();
        }
    }
    /** Removes the element from in front of queue and returns that element. */
    int pop() {
        copy(stk,cache);

        int ans = cache.top();
        cache.pop();
        copy(cache,stk);
        return ans;

    }

    /** Get the front element. */
    int peek() {

        copy(stk,cache);
        int ans2 = cache.top();

        copy(cache,stk);
        return ans2;

    }

    /** Returns whether the queue is empty. */
    bool empty() {

        return stk.empty();
    }
};

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * bool param_4 = obj.empty();
 */


活动打卡代码 AcWing 862. 三元组排序

Weiiii.
8天前
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

#include <bits/stdc++.h>

using namespace std;

const int N =10010;
struct IN
{
    int x;
    double y;
    string z;
}in[N];

bool cmp(IN a,IN b)
{
    return a.x < b.x;
}


int main()
{
    int n;
    cin >> n;

    for(int i=0;i<n;i++)
    {
        cin >>in[i].x;
        cin>> in[i].y;
        cin >> in[i].z;

    }

    sort(in,in+n,cmp);

    for(int i=0;i<n;i++)
{
    cout << in[i].x<<" ";
    printf("%.2f ",in[i].y);
    cout  << in[i].z <<endl;
}

    return 0;
}



Weiiii.
8天前
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

class Solution {
public:
    int NumberOf1(int n) {
        int ans = 0;
        for(int i=0;i<32;i++)
        {
            ans += (n>>i) & 1;

        }

        return ans;


    }
};


活动打卡代码 AcWing 51. 数字排列

Weiiii.
8天前
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

class Solution {
public:
    vector<vector<int>> permutation(vector<int>& nums) {

        vector<vector<int>>  ans;
        sort(nums.begin(),nums.end());

        do
        {
            ans.push_back(nums);
        }
        while(next_permutation(nums.begin(),nums.end()));

        return ans;

    }
};



Weiiii.
9天前
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

class Solution {
public:
    vector<int> findNumbersWithSum(vector<int>& nums, int target) {

        unordered_set<int> S;

        for(auto x:nums)
        {
            if(S.count(target-x))   return {target-x,x};
            S.insert(x);
        }


    }
};


活动打卡代码 AcWing 53. 最小的k个数

Weiiii.
9天前
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

class Solution {
public:
    vector<int> getLeastNumbers_Solution(vector<int> input, int k) {

        vector<int> ans;

        int len =input.size();
        sort(input.begin(),input.end());

        for(int i=0;i<k;i++)
        {
            ans.push_back(input[i]);

        }

        return ans;

    }
};



Weiiii.
9天前
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~


/**
 * 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) {
        auto  dummy = new ListNode(-1);
        dummy->next=head;
         auto p=dummy;

         while(p->next)
         {
             auto q =p->next;

             while(q->next && q->next->val==p->next->val)  q=q->next;

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

             }


        return dummy->next;


    }
};



Weiiii.
9天前
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~


/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *findFirstCommonNode(ListNode *headA, ListNode *headB) {

     auto p= headA;
     auto q = headB;
     while(p!=q)
     {
         if(p) p=p->next;
         else p=headB;
         if(q)  q=q->next;
         else q=headA;
     }

     return p;


    }
};



Weiiii.
9天前
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~


class Solution {
public:
    void reOrderArray(vector<int> &array) {

     int len=array.size();


     vector<int> ans;
     vector<bool> p;
     for(int i=0;i<len;i++)
     {
         p.push_back(true);
     }

     for(int i=0;i<len;i++)
     {
         if(array[i]%2!=0)
         {
             ans.push_back(array[i]);
             p[i]=false;
         }
     }

       for(int i=0;i<len;i++)
     {
         if(p[i]==true)
         {
             ans.push_back(array[i]);
         }
     }

     for(int i=0;i<len;i++)
     {
         array[i]=ans[i];
     }

    }
};



Weiiii.
9天前
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    vector<int> printListReversingly(ListNode* head) {

        vector<int> note;
        vector<int> ans;
        if(!head)   return note;
        auto p=head;
        while(p)
        {
            note.push_back(p->val);
            p=p->next;
        }


        int len=note.size(); 

        for(int i=len-1;i>=0;i--)
        {
            ans.push_back(note[i]);
        }

        return ans;

    }
};