0tps

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

Dcchen @ 2023-10-12 17:54:46

#include<algorithm>
#include<string.h>
#include<iostream>
using namespace std;
int n,q;
string id[1005],want[1005],sttd[1005];
int hlong[1005];
void sss(int k){
    string st;
    for(int i=0;i<n;i++){
        for(int j=0;j<k;j++){
            id[i][j]=sttd[i][n-j];
        }
    }
    for(int i=0;i<n;i++){
        if(id[i]==want[k])
        sttd[i]<st?st=st:st=sttd[i];
    }
    st.size()>=1?cout<<st<<endl:cout<<-1<<endl;
    for(int i=0;i<n;i++){
        id[i]=sttd[i];
    }
}
int main(){
    cin>>n>>q;
    for(int i=0;i<n;i++)cin>>id[i];
    for(int i=0;i<q;i++)cin>>hlong[i]>>sttd[i];
    /*if(n<=2){
        while(q--){
            cout<<id[0];
        }
        return 0;
    }*/
    for(int i=0;i<q;i++){
        sss(i);
    }
    return 0;
}

by E_RONALDO @ 2023-10-13 17:39:46

怎么了


by E_RONALDO @ 2023-10-13 17:41:02

#include <iostream>
#include<algorithm>
#include <cmath>
using namespace std;
int a[10000];
int main(){
    int n,m;
    cin>>n>>m;
    for (int i=0;i<n;i++) {
        cin>>a[i];
    }
    sort(a,a+n);
    while (m--) {
        int x,y;
        cin>>x>>y;
        for (int i=0;i<n;i++) {
            if (y==a[i] % (int)pow(10,x)) {
                cout<<a[i]<<endl;
                break;
            }
            if (i==n-1) {
                cout<<-1<< endl;
            }
        }
    }
    return 0;
}

by zhang13095534103 @ 2024-01-14 18:38:55

#include<bits/stdc++.h>
using namespace std;
int n,q;
int a[1005];
bool check(int p,int k,int len){
    for(int i=1;i<=len;i++){
        if(p%10 !=k%10) return false;
        p/=10;k/=10;
    }
    return true;
}
int main(){
    cin>>n>>q;
    for(int i=1;i<=n;i++) cin>>a[i];
    while(q--){
        int m,num;cin>>m>>num;
        int minn=1e8;
        for(int i=1;i<=n;i++){
            if(check(a[i],num,m)){
                minn =min(minn,a[i]);
            }
        }
        if(minn==1e8) cout<<-1<<endl;
        else cout<<minn<<endl;
    }
    return 0;
} 

|