题解:P14505 [NCPC 2025] km/h

· · 题解

简单模拟题。每次遇到限速时直接输出限速,同时用一个变量维护国家限速,具体的,若当前限速为 a,则更新国家限速为当前国家限速与首个大于 a 且能够被 10 整除的数。当遇到解除限速时,输出国家限速即可。马蜂良好

代码如下:

#include<bits/stdc++.h>
#define int long long

using namespace std;
int n,a,maxn;
string s;

inline int pre()
{
    int l=s.size(),res=0;
    for(int i=0;i<l;i++)(res*=10)+=s[i]-'0';
    return res;
}

inline int find()
{
    int res=a;
    (res+=10)-=res%10;
    return res;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin>>n;
    while(n--)
    {
        cin>>s;
        if(s[0]=='/')cout<<maxn<<"\n";
        else
        {
            cout<<s<<"\n";
            a=pre();
            maxn=max(maxn,find());
        }
    }
    return 0;
}