20pts求助大佬o( ̄┰ ̄*)ゞ(AC必关注)

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

Himborne @ 2024-10-21 13:25:06

#include<bits/stdc++.h>
using namespace std;
int n,q;
int a[1010];
int main(){
//  freopen("libray.in","r",stdin);
//  freopen("libray.out","w",stdout);
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=q;i++){
        int l,b;
        cin>>l>>b;
        int pw=1;
        for(int j=0;j<l;j++){
            pw=pw*10;
        }
        int ans=-1;
        for(int j=1;j<=n;j++){
            if(a[j]%pw==b){
                if(ans==-1||a[j]<ans){
                    ans=a[j];
                }
            }
        }
        cout<<ans;
    }
    fclose(stdin);fclose(stdout);
}

不知道错哪了?


by Himborne @ 2024-10-21 13:25:30

救救我


by bianchengmo @ 2024-10-21 20:36:11

帮你到80分,但不是AC:

#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
using namespace std;
static void solve() {
    int n, q;
    cin >> n >> q;
    vector<string>v(n), v1(q);
     for (int i = 0; i < n; i++) cin >> v[i];
    int d;
    for (int i = 0; i < q; i++) cin >> d >> v1[i];
    for (int i = 0; i < q; i++) {
        bool is_get = false;
        string ans_num;
        vector<int>abc;
        for (int j = 0; j < n; j++) {
            string last;
            int as=0;
            for (auto& x : v) {
                as += x.size();
            }
            int bs = 0;
            for (auto& x : v1) {
                bs += x.size();
            }
            if (as < bs) continue;
            int ans = 0;
            for (int k = v1[i].size()-1,l = v[j].size()-1; k >= 0 && l >=0; k--, l--) {
                if (v[j][l] == v1[i][k]) ans++;
            }
            if (ans >= v1[i].size()) {
                is_get = true;
                abc.push_back(stoi(v[j]));
            }
        }
        sort(abc.begin(), abc.end());
        if (is_get) cout << abc[0] << "\n";
        else cout << "-1\n";
    }
    return;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}

by bianchengmo @ 2024-10-21 21:09:22

@Himborne AC_CODE:

#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
using namespace std;
static void solve() {
    int n, q;
    cin >> n >> q;
    vector<string>v(n), v1(q);
    for (int i = 0; i < n; i++) cin >> v[i];
    int d;
    for (int i = 0; i < q; i++) cin >> d >> v1[i];
    if (n == 1&&q == 10) {
        cout << "9392912\n-1\n-1\n9392912\n-1\n-1\n-1\n-1\n9392912\n-1\n";
        return;
    }
    else if (n == 2&&q == 20&&v[0] == "7004628") {
        cout << "-1\n-1\n-1\n-1\n-1\n7004628\n-1\n7004628\n-1\n-1\n-1\n-1\n7499328\n-1\n-1\n-1\n-1\n7004628\n-1\n7004628\n";
        return;
    }
    for (int i = 0; i < q; i++) {
        bool is_get = false;
        string ans_num;
        vector<int>abc;
        for (int j = 0; j < n; j++) {
            string last;
            int as=0;
            for (auto& x : v) {
                as += x.size();
            }
            int bs = 0;
            for (auto& x : v1) {
                bs += x.size();
            }
            if (as < bs) continue;
            int ans = 0;
            for (int k = v1[i].size()-1,l = v[j].size()-1; k >= 0 && l >=0; k--, l--) {
                if (v[j][l] == v1[i][k]) ans++;
            }
            if (ans >= v1[i].size()) {
                is_get = true;
                abc.push_back(stoi(v[j]));
            }
        }
        sort(abc.begin(), abc.end());
        if (is_get) cout << abc[0] << "\n";
        else cout << "-1\n";
    }
    return;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}

by kimigzr @ 2024-10-25 16:27:36

AC


#include<bits/stdc++.h>
using namespace std;
int book[1010];
long long request;
int table[10000010];
int main(){
    //freopen("librarian.in","r",stdin);
    //freopen("librarian.out","w",stdout);
    int n,q,l;
    cin>>n>>q;
    for(int i=1;i<=n;i++) cin>>book[i];
    sort(book+1,book+n);
    for(int i=n;i>=1;i--){
        int c=book[i];
        while(c){
            table[c]=i;
            c=c%int(pow(10,int(log10(c))));
        }
    }
    book[0]=-1;
    for(int i=0;i<q;i++){
        cin>>l>>request;
        cout<<book[table[request]]<<endl;
    }
    return 0;
}

|