https://www.acwing.com/activity/content/2589/

这场周赛也很简单,除了C我在赛场上写的时候有点小bug,赛时没改出来,哎,真废啊

4713. 反转字符串

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL INF=1e9;
const LL N=5000200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        string s,c;
        cin>>s>>c;
        bool flag=true;
        reverse(s.begin(),s.end());
        if(s==c) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

4714. 数对

手动模拟一下就可以找到规律

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL INF=1e9;
const LL N=5000200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        map<char,LL> mp;
        for(LL i=0;i<s.size();i++)
        {
            mp[s[i]]++;
        }
        LL sum=0;
        for(LL i=48;i<=57;i++)
        {
            char op=(char)i;
            //cout<<op<<" ";
            sum+=(LL)(mp[op]*mp[op]);
        }
        for(int i=97;i<=122;i++)
        {
            char op=(char)i;
            //cout<<op<<" ";
            sum+=(LL)(mp[op]*mp[op]);
        }
        cout<<sum<<endl;
        mp.clear();
    }
    return 0;
}

4715. 构造数组

题目大意:

按照字符串给出的相邻两两数字的比较,构造出这样的数组。

一定会有答案。
输入样例1:
5
><><
输出样例1:
2 1 2 1 2
输入样例2:
5
=<<<
输出样例2:
1 1 2 3 4

数据范围在2000内,直接暴力。固定往后找的同时,遇到不符合条件的直接回溯更正。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=200200,M=2002;
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        string s;
        cin>>s;
        s=" "+s;
        a[0]=1;
        for(int i=1;i<=n-1;i++)
        {
            if(s[i]=='=') a[i]=a[i-1];
            else if(s[i]=='<') a[i]=a[i-1]+1;
            else if(s[i]=='>')
            {
                a[i]=1;
                if(a[i-1]==1) a[i]=0;
            }
            if(a[i]<=0)
            {
                a[i]=1;
                int j=i;
                while(j>=1)
                {
                    if(s[j]=='>'&&a[j-1]<(a[j]+1)) a[j-1]=a[j]+1;
                    else if(s[j]=='=') a[j-1]=a[j];
                    else break;
                    j--;
                }
            }
        }
        for(int i=0;i<=n-1;i++)
        {
            cout<<a[i]<<" ";
        }
        cout<<endl;
        s.clear();
    }
    return 0;
}

原文地址:http://www.cnblogs.com/Vivian-0918/p/16866718.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性