第六次寒假训练赛题解

第六次寒假训练赛题解

A CodeForces - 21A

简单模拟,模就完事了

#include<bits/stdc++.h>
using namespace std;
bool judge(int c)
{
    return (c>=97&&c<=122)||(c>=65&&c<=90)||(c>=48&&c<=57)||c==95;
}
int main()
{
    int t=0;
    int c=getchar();
    while(judge(c))
    {
        t++;
        c=getchar();
    }
    if(t>=1&&t<=16&&c=='@')
    {
L:
        t=0;
        c=getchar();
        while(judge(c))
        {
            t++;
            c=getchar();
        }
        if(t>=1&&t<=16)
        {
            if(c=='\n')
                cout << "YES" << endl;
            else if(c=='.')
                goto L;
            else if(c=='/')
            {
                t=0;
                c=getchar();
                while(judge(c))
                {
                    t++;
                    c=getchar();
                }
                if(t>=1&&t<=16&&c=='\n')
                    cout << "YES" << endl;
                else cout << "NO" << endl;
            }else cout << "NO" << endl;
        }else cout << "NO" << endl;
    } else cout << "NO" << endl;
    return 0;
}

B CodeForces - 49B

简单模拟,模就完事了

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    int t=a,d=2;
    while(t)
    {
        d=max(d,t%10+1);
        t/=10;
    }
    t=b;
    while(t)
    {
        d=max(d,t%10+1);
        t/=10;
    }
    t=0;
    int k=1;
    while(a||b)
    {
        t+=(a%10)*k;
        t+=(b%10)*k;
        a/=10;
        b/=10;
        k*=d;
    }
    int ans=0;
    while(t)
    {
        t/=d;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

C CodeForces - 128B

优先队列,后缀自动机也可,这里只写优先队列的方法

#include <bits/stdc++.h>
using namespace std;
struct str
{
    string s;
    int num;
    bool operator <(const str &x)const
    {
        if(x.s==s)
            return num>x.num;
        return s>x.s;
    }
} x;
int main()
{
    priority_queue<str> q;
    string s;
    int n;
    cin>>s;
    cin>>n;
    for(int i=0; i<s.size(); i++)
    {
        x.s=s[i];
        x.num=i;
        q.push(x);
    }
    while(!q.empty())
    {
        x=q.top();
        q.pop();
        n--;
        if(!n)
            break;
        if(x.num<s.size()-1)
        {
            x.num++;
            x.s+=s[x.num];
            q.push(x);
        }
    }
    if(n)
        cout<<"No such line."<<endl;
    else
        cout<<x.s<<endl;
return 0;
}

D CodeForces - 190C

简单递归一下就行

#include <bits/stdc++.h>
using namespace std;
string s,ans;
bool flag= true;
void input()
{
    if (cin >> s)
    {
        ans+=s;
        if (s=="pair")
        {
            ans+='<';
            input();
            ans+=',';
            input();
            ans+='>';
        }
    }
    else
        flag= false;
}

int main()
{
    cin >> s;
    input();
    if (cin >> s)
        flag= false;
    if(flag)
        cout << ans << endl;
    else
        cout << "Error occurred" << endl;
    return 0;
}

E CodeForces - 798B

暴力算最值

#include<bits/stdc++.h>
using namespace std;
int n;
string a[55],t;
int sum=1<<30;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        int ans=0;
        for(int j=0;j<n;j++)
        {
            if(i==j) continue;
            t=a[j]+a[j];
            if(t.find(a[i])==-1)
            {
                cout<<-1<<endl;
                return 0;
            }
            ans+=t.find(a[i]);
        }
        sum=min(ans,sum);
    }
    cout << sum << endl;
    return 0;
}

F CodeForces - 1043C

字典序最小的时候s必然是前面全是a,后面全是b这个样子,以此为规则模拟一下会发现只要是s[i]!=s[i+1]就应该翻转

#include <bits/stdc++.h>
using namespace std;
string s,ans="";
int main()
{
    cin >> s;
    for(int i=0;i<s.size()-1;i++)
    {
        if(s[i]!=s[i+1])ans+="1 ";
        else ans+="0 ";
    }
    if(s[s.size()-1]=='a')ans+="1";
    else ans+="0";
    cout << ans << endl;
    return 0;
}
全部评论

相关推荐

||&nbsp;先说下主播个人情况:211本,暑期实习之前有过一段中大厂的后端实习,暑期拿过腾讯的实习offer,综合考虑业务和语言最终去了美团。实习期间体感还是不错的,5月初去的,去了就一直急着要需求做,担心因为没有产出导致转正失败,在第二个星期就和mt透露我希望能够留用。虽然第一个由于美团新人landing的友好性基本没做什么需求,但是后面也写出了小2w行的代码量(不包含单测)。中期经常主动加班赶需求,经常持续一两个星期加班到10点甚至更后面。mt对我确实不错,也是言传身教,实习期间给我讲了很多关于单测,ddd,set化等的理解,也是受益匪浅,此外在做需求的时候,也能看出把比较有含金量的部分交给我做...
菜菜菜小白菜菜菜:我在字节实习了四个月,有转正的压力所以周末大部分也在公司自学,也是因为一些原因转正拖的很久,这个点还没答辩,过段时间才回去答辩。整个不确定性的焦虑贯穿了我的秋招三个月,我也曾经犹豫过是不是应该放弃转正走秋招更快,最后因为沉没成本一直舍不得放弃,前前后后七个月真的挺累的,尤其是没有来字节实习的同学已经校招拿到意向时更加焦虑。这段时间也跟mentor聊了很多次,他告诉我未来工作上或者生活上,比这些更头疼的事情会更多,关键还是要调整好自己的心态。转正没有通过从过程上来看其实跟你自身没太大的关系,拖了三个月不出结果显然是ld的问题,并且今年美团最近的开奖大家似乎都不是很乐观,所以不去也罢。我在字节实习的时候,6月份有一个赶上春招末期的25届同事刚面进来,也拿到了小sp的薪水。不要对这件事有太大的压力,时代的问题罢了
点赞 评论 收藏
分享
叁六玖:不买课还想秋招
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务