NOIP2017 普及组复赛参考解析

题目传送

P3954 [NOIP2017 普及组] 成绩

  • 简单题,没说的
点击查看代码
#include<bits/stdc++.h>
using namespace std;

int main() {
    int a,b,c; cin>>a>>b>>c;
    cout<<a*0.2+b*0.3+c*0.5;
    return 0;
}

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

  • 数据很小,排序+枚举即可
  • 排序的时候需要自定义排序规则,字符串默认排序是按照字典序排序。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int n,q,a;
string s[N],b;
bool cmp(string a,string b){
    if(a.size()!=b.size()) return a.size()<b.size();
    return a<b;
}
int main(){
//    freopen("data.in", "r", stdin);
    cin>>n>>q;
    for(int i=1; i<=n; i++) cin>>s[i];
    sort(s+1,s+1+n,cmp);
    while(q--){
        cin>>a>>b; bool flag=0;
        for(int i=1; i<=n; i++){
            int k=s[i].size();
            if(k>=a && s[i].substr(k-a)==b){
                cout<<s[i]<<endl; flag=1; break;
            }
        }
        if(!flag) cout<<-1<<endl;
    }
    return 0;
}

P3956 [NOIP2017 普及组] 棋盘

P3957 [NOIP2017 普及组] 跳房子

posted @ 2022-10-21 09:13  HelloHeBin  阅读(159)  评论(0)    收藏  举报