Codeforces Round 855 (Div. 3)

第一题 A. Is It a Cat?

#include <iostream>
#include <cstdio>
#include <cctype>

using namespace std;

string str = "meow";

void solve()
{
    int n;cin >> n;
    string s; cin >> s;
    for(int i = 0;i < n;i++) s[i] = tolower(s[i]);
    // for(int i = 0;i < n;i++) cout << s[i];
    // cout << endl;
    int j = 0;
    if(s[0] != 'm'){
        cout << "NO" << endl;
        return ;
    }
    for(int i = 0;i < n ;i++)
    {
        if(s[i + 1] != s[i]) 
        {
            j++;
            if(s[i + 1] != str[j])
            {
                cout   << "NO" << endl;
                return ;
            }
        }
    }
    if(j == 4)
    cout << "YES" << endl;
    else cout << "NO" << endl;
    
}

int main()
{
    int t;cin >> t;
    while(t--)
    {
        solve();
    }
}

 其中函数 tolower 是将大写字母转化为小写字母 ;函数 toupper 则是将小写字母转化为大写字母

存在于 <cctype> 头文件中

#include <iostream>
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;

string str = "meow";

void solve()
{
    int n;cin >> n;
    string s; cin >> s;
    for(int i = 0;i < n;i++) s[i] = tolower(s[i]);
    s.erase(unique(s.begin(),s.end()),s.end());
    if(s == "meow") cout << "YES" << endl;
    else cout << "NO" << endl;
    return ;
}

int main()
{
    int t;cin >> t;
    while(t--)
    {
        solve();
    }
}

用到了 unique 去重 !!!!!

第二题 

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
const int N = 150;
int cnt[N];

void solve()
{
    for(int i = 0;i < 150;i++) cnt[i] = 0;
    int n,k;cin >> n >> k;
    string s;cin >> s;
    for(int i = 0;i < n;i++) 
    {
        int nu = s[i];
        cnt[nu]++;
    }
    int res = 0;
   
      for(int i = 'A';i <= 'Z'; i++){
        res += min(cnt[i],cnt[i+32]);
        if(k != 0){
            int maxt = max(cnt[i],cnt[i+32]);
            int mint = min(cnt[i],cnt[i+32]);
            res += min(k,(maxt-mint)/2);
            k -= min(k,(maxt-mint)/2);
        }
    }

    cout << res << endl;
}
int main()
{
    int t; cin >> t;
    while(t--) solve();
    return 0;
}

A —— 64 ;a ——97

第三题 C1 第四题C2 用到了优先队列 大根堆排序

#include <iostream>
#include <cstdio>
#include <queue>

using namespace std;
const int N = 1e5 +10;
int a[N];
typedef long long ll;

void solve()
{
    int n;cin >> n;
    priority_queue<int> q;
    queue<int> num;
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i] == 0)
        {
            if(!q.empty())
            {
                num.push(q.top());
                q.pop();
            }
        }
        else q.push(a[i]);
    }
    ll res = 0;
    while(num.size())
    {
        res += num.front();
        num.pop();
    }
    cout << res << endl;
}

int main()
{
    int t; cin >> t;
    while(t--) solve();
    
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值