头像

DegenZ




离线:13小时前


最近来访(3)
用户头像
私の世界では私は神です

活动打卡代码 AcWing 786. 第k个数

DegenZ
14小时前
#include <iostream>

using namespace std;

const int N = 100010;
int a[N];

void quick_sort(int a[], int l, int r)
{
    if (l >= r) return;

    int i = l - 1, j = r + 1, x = a[l + r >> 1];
        while (i < j)
        {
            do i ++ ; while (a[i] < x);
            do j -- ; while (a[j] > x);
            if (i < j) swap (a[i], a[j]); 
        }
        quick_sort(a, l, j), quick_sort(a, j + 1, r);
}

int main()
{
    int m, n;
    cin >> m >> n;
    for (int i = 0; i < m; i ++ ) cin >> a[i];

    quick_sort(a, 0, m - 1);

    for (int i = 0; i < m; i ++ ); 
    cout << a[n - 1];

    return 0;
}


活动打卡代码 AcWing 785. 快速排序

DegenZ
14小时前
#include <iostream>
#include <cstring>

using namespace std;

const int N = 100010;
int a[N];

void quick_sort(int q[], int l, int r)
{
    if (l >= r) return;

    int i = l - 1, j = r + 1, x = q[l + r >> 1];
    while (i < j)
    {
        while (q[++i] < x);
        while (q[--j] > x);
        if (i < j) swap(q[i], q[j]);

    }
    quick_sort(q, l, j), quick_sort(q, j + 1, r);
}


int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i ++ ) cin >> a[i];

    quick_sort(a, 0, n - 1);

    for (int i = 0; i < n; i ++ ) cout << a[i] << ' ';

    return 0;
}


活动打卡代码 AcWing 822. 走方格

DegenZ
20小时前
#include <iostream>

using namespace std;

int n, m;
int ans;

void dfs (int x, int y)
{
    if (x == n && y == m) ans ++ ;
    else
    {
        if (x < n) dfs(x + 1, y);
        if (y < m) dfs(x, y + 1);
    }

}

int main()
{

    cin >> n >> m;
    dfs(0, 0);
    cout << ans << endl;
    return 0;
}



DegenZ
21小时前
#include <iostream>
#include <cstring>

int c[26];
const int N = 100000;

using namespace std;

int main()
{

    char s[N];
    cin >> s;
    // int len = strlen(s);

    for (int i = 0; s[i]; i ++ ) c[s[i] - 'a'] ++ ;

    for (int i = 0; s[i]; i ++ )
        if (c[s[i] - 'a'] == 1)
        {
            cout << s[i] << endl;
            return 0 ;
        }
    cout << "no" << endl;

    return 0;
}



DegenZ
1天前
#include <iostream>

using namespace std;

int main()
{
    string s, s1, s2;

    char c;
    while (cin >> c, c != ',') s += c;
    while (cin >> c, c!= ',') s1 += c;
    while (cin >> c) s2 += c;

    if (s.size() < s1.size() || s.size() < s2.size()) cout << "-1" << endl;

    else
    {
        int i = 0;
        for (; i + s1.size()<= s.size(); i ++ )
        {
            int k = 0;
            while (k < s1.size())
            {
                if (s[i + k] != s1[k]) break;
                k ++ ;
            }
            if (k == s1.size()) break;
        }

       int j = s.size() - s2.size();
       for (; j >= 0; j -- )
       {
            int k = 0;
            while (k < s2.size())
            {
                if (s[j + k] != s2[k]) break;
                k ++ ;
            }
            if (k == s2.size()) break;
       }


        i += s1.size() - 1;
        if (i >= j) cout << "-1" << endl;
        else printf("%d", j - i - 1);
    }

    return 0;
}


活动打卡代码 AcWing 777. 字符串乘方

DegenZ
1天前
#include <iostream>

using namespace std;

int main()
{
    string s;
    while (cin >> s, s != ".")
    {
        int len = s.size();

        for (int n = len; n; n -- )
        {
            if (len % n == 0)
            {
                int m = len / n;
                string r = s.substr(0, m);
                string res;
                for (int i = 0; i < n; i ++ ) res += r;

                if (res == s)
                {
                    cout << n << endl;
                    break;
                }
            }
        }
    }
    return 0;
}


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

DegenZ
1天前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 10001;

struct Data
{
    int x;
    double y;
    string z;

    bool operator < (const Data &t) const
    {
        return x < t.x;
    }

}a[N];

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

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

    sort(a, a + n);

    for (int i = 0; i < n; i ++ ) 
        printf("%d %.2lf %s\n", a[i].x, a[i].y, a[i].z.c_str());

    return 0;
}



DegenZ
1天前
class Solution {
public:
    int NumberOf1(int n) {
        int c = 0;
        for (int i = 0; i < 32; i ++ )
            if (n >> i & 1)
                c ++;
        return c;
    }
};



DegenZ
1天前
class Solution {
public:
    void reOrderArray(vector<int> &array) {
        int i = 0, j = array.size() - 1;
        while (i < j)
        {
                while (i < j && array[i] % 2 != 0) i ++ ;
                while (i < j && array[j] % 2 == 0) j -- ;
                if (i < j) swap(array[i], array[j]);
        }

    }
};


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

DegenZ
1天前
class Solution {
public:
    vector<int> getLeastNumbers_Solution(vector<int> input, int k) {
        vector<int> res;
        sort(input.begin(), input.end());
        for (int i = 0; i < k; i ++ ) res.push_back(input[i]);
        for (int i = 0; i < 2; i ++ ) 
        return res;
    }
};