全部RE

P1923 【深基9.例4】求第 k 小的数

MuYuMC @ 2024-05-04 21:04:40

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
int A[100000000];
int main()
{
    int n,x,m,i;
    cin >> n >> m;
    for(i = 1;i <= n;i++)
    {
        cin >> x;
        A[x]++;
    }
    x = -1;
    for(i = 1;i <= 1000000000;i++)
    {
        if(A[i] != 0)
        {
            x++;
            if(x == m)
            {
                cout << i;
                break;
            }
        }
    }
    return 0;
}

by MuYuMC @ 2024-05-07 12:20:02

@zhengpie hh,我都是自己写

#include <iostream>
#include <cstring>
using namespace std;
int A[2000]; 
int B[2000];
int sum[99999];
int main()
{
    int n,i,k;
    string s1,s2;
    cin >> s1 >> s2;
    A[0] = s1.size();
    B[0] = s2.size(); 
    for(i = 1;i <= s1.size();i++)
    {
        A[i] = s1[A[0] - i] - '0';
    }
    for(i = 1;i <= s2.size();i++)
    {
        B[i] = s2[B[0] - i] - '0';
    }
    k = max(A[0],B[0]);
    for(i = 1;i <= k;i++)
    {
        A[i + 1] += (A[i] + B[i]) / 10;
        A[i] = (A[i] + B[i]) % 10;
    }
    if(A[k + 1] != 0)k++;
    for(i = k;i >= 1;i--)cout << A[i];
    return 0;
} 

by MuYuMC @ 2024-05-07 12:24:16

@zhengpie 哎?!我啥时候我蓝名了?


by MuYuMC @ 2024-05-07 12:24:44

@zhengpie 哎?!我啥时候我蓝名了?


上一页 |