总是不对,也没找到错哪了

P3955 [NOIP2017 普及组] 图书管理员

Dpf20120621 @ 2023-12-25 20:39:19

#include<bits/stdc++.h>
using namespace std;
int a[1001],b[1001],w[1001];
int main(){
    int n,q;
    bool f;
    cin>>n>>q;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<q;i++)cin>>w[i]>>b[i];
    sort(a,a+n);
    for(int i=0;i<n;i++){
        int ws=pow(10,w[i]);
        f=true;
        for(int j=0;j<q;j++){
            if(a[i]%ws==b[i]){
                cout<<a[i];
                f=false;
                break;
            }
        }
        if(f)cout<<"-1";
        cout<<endl;
    }
    return 0;
}
/*
5 5
2123
1123
23
24
24
2 23
3 123
3 124
2 12
2 12

*/

希望有解


by abc_abc_abc @ 2024-02-28 18:17:59

看不懂 我这个小学生写了个代码!!!(c++)

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int arr[10010],n,q,a,b,m,min;
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    for (int i = 1; i <= q; i++)
    {
        m = 1;
        min = 10000010;
        cin >> a >> b;
        for (int j = 1; j <= a; j++)
        {
            m *= 10;
        }
        for (int j = 1; j <= n; j++)
        {
            if (arr[j] % m == b && arr[j] < min)
            {
                min = arr[j];
            }
        }
        if (min == 10000010)
        {
            cout << -1 << endl;
        }
        else
        {
            cout << min << endl;
        }
    }
    return 0;
}

by fanhaoxuan0110 @ 2024-05-01 15:41:09

你几年级


|