零点工作室暑假集训(AtCoder--ABC291)

A - camel Case

题意:给定一个字符串,找到唯一存在的大写字母的位置

S是一个长度在2和100之间的字符串,由大写和小写英文字母组成。
S正好有一个大写字母。

#include <bits/stdc++.h>

using namespace std;

string s;

int main()
{
    cin >> s;
    for(int i = 0; i < s.size(); i ++)
    {
        if(s[i] >= 'A' && s[i] <= 'Z') cout << i + 1 << endl;
    }
    
    return 0;
}

B - Trimmed MeanN
题意:给你一个长度为5N的数组,剔除N 个最小值,N个最大值,求剩下的数的平均值

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100010;

int n;
double a[N];
double sum;

int main()
{
    cin >> n;
    for(int i = 1; i <= 5 * n; i ++)
    {
        cin >> a[i];
    }
    
    sort(a + 1, a + 5 * n + 1);
    
    
    for(int i = n + 1; i <= 5 * n - n; i ++)
    {
        sum += a[i];
    }

    printf("%.15lf", sum / (5 * n - 2 * n));
    
    return 0;
}

C - LRUD Instructions 2
题意:你在二维平面的起点( 0 , 0 ) (0,0)(0,0)上,每次可以上下左右移动,给你一个字符串S SS表示移动序列

( x + 1 , y ) (x+1,y)(x+1,y) if the i-th character of S is R;
( x − 1 , y ) (x-1,y)(x−1,y) if the i-th character of S is L;
( x , y + 1 ) (x,y+1)(x,y+1) if the i-th character of S is U;
( x , y − 1 ) (x,y-1)(x,y−1) if the i-th character of S is D,
你需要判断该移动序列有没有经过重复点的情况

1 ≤ N ≤ 2 × 1e5

可使用map函数进行操作。走过的点标记为1,未走过的标记为0

#include<iostream>
#include<map>

using namespace std;

int n, i, j;
string s;

int main()
{
    map<int, map<int, int>> p;
    p[0][0] = 1;
    cin >> n >> s;
    for (int k = 0; k < n; k ++)
    {
        if (s[k] == 'R' && p[i][j + 1] == 0)
        {
            j ++;
            p[i][j] ++;
        }
        else if (s[k] == 'L' && p[i][j - 1] == 0)
        {
            j --;
            p[i][j] ++;
        }
        else if (s[k] == 'U' && p[i + 1][j] == 0)
        {
            i ++;
            p[i][j] ++;
        }
        else if (s[k] == 'D' && p[i - 1][j] == 0)
        {
            i --;
            p[i][j] ++;
        }
        else
        {
            cout << "Yes";
            return 0;
        }
    }
        cout << "No";
        return 0;
}


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值