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;
}