果咩
1456.定长子串中元音的最大数目
题目链接:https://leetcode.cn/problems/maximum-number-of-vowels-in-a-substring-of-given-length/description/
题解代码:
class Solution {
public:
int maxVowels(string s, int k) {
int ans=0,vowel=0;
for(int i=0;i<s.size();i++){
if(s[i]=='a'||s[i]=='e'||s[i]=='o'||s[i]=='i'||s[i]=='u') vowel++;
if(i<k-1) continue;
ans=ans>vowel?ans:vowel;
char r=s[i-k+1];
if (r == 'a' || r == 'e' || r == 'i' || r == 'o' || r == 'u') vowel--;
}
return ans;
}
};
D. Range = √Sum
题目链接:https://codeforces.com/contest/1758/problem/D
题解代码:
//数学不好抄了题解思路
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if (n % 2 == 0) {
vector<int> result;
for (int i = n / 2; i <= n / 2 + n; ++i) {
if (i != n) {
result.push_back(i);
}
}
for (int i = 0; i < result.size(); ++i) {
if (i > 0) cout << " ";
cout << result[i];
}
cout << endl;
} else {
vector<int> a(n);
for (int i = 0; i < n; ++i) {
a[i] = n / 2 + 3 + i;
}
a[0] -= 1;
a[n - 1] += 1;
a[n - 2] += 1;
for (int i = 0; i < n; ++i) {
if (i > 0) cout << " ";
cout << a[i];
}
cout << endl;
}
}
return 0;
}
C. Hossam and Trainees不会写
D. Sakurako's Hobby
题目链接:https://codeforces.com/problemset/problem/2008/D
题解代码:
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> p(n + 1);
vector<int> F(n + 1, 0);
vector<bool> visited(n + 1, false);
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
string s;
cin >> s;
for (int i = 1; i <= n; i++) {
if (!visited[i]) {
int l = i;
int count = 0;
while (!visited[l]) {
visited[l] = true;
if (s[l - 1] == '0') count++;
l = p[l];
}
l = i;
while (true) {
F[l] = count;
l = p[l];
if (l == i) break;
}
}
}
for (int i = 1; i <= n; i++) {
cout << F[i] << " ";
}
cout << endl;
}
return 0;
}
P1803 凌乱的yyy / 线段覆盖
题目链接:https://www.luogu.com.cn/problem/P1803
题解代码:
#include<bits/stdc++.h>
using namespace std;
int n,sum=1;
struct E{
int a,b;
}s[1000005];
bool cmp(E x,E y){
return x.b<y.b;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>s[i].a>>s[i].b;
sort(s+1,s+n+1,cmp);
for(int i=2;i<=n;i++){
if(s[i].a>=s[i-1].b) sum++;
else{
s[i].b=s[i-1].b;
s[i].a=s[i-1].a;
}
}
cout<<sum;
return 0;
}
D. Slavic's Exam
题目链接:https://codeforces.com/contest/1999/problem/D
题解代码:
#include <bits/stdc++.h>
using namespace std;
int main() {
int te; cin >> te;
while(te--) {
string s, t; cin >> s >> t;
int x = 0;
for(int i = 0; i < (int)s.size(); ++i) {
if(s[i] == '?') {
if(x < (int)t.size()) s[i] = t[x++];
else s[i] = 'a';
} else if(s[i] == t[x]) ++x;
}
if(x >= t.size()) cout << "YES\n" << s << "\n";
else cout << "NO\n";
}
return 0;
}
P1106 删数问题
题目链接:https://www.luogu.com.cn/problem/P1106
题解代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
string n;
int s,i;
cin>>n>>s;
while(s){
i=0;
while(n[i]<=n[i+1]) i++;
n.erase(i,1);
s--;
}
while(n[0]=='0'&&n.size()>1) n.erase(0,1);
cout<<n;
return 0;
}
B. Palindromic Numbers
题目链接:https://codeforces.com/contest/1700/problem/B
题解代码:
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
if (s[0] != '9') {
for (char c : s) {
cout << 9 - (c - '0');
}
cout << endl;
return;
}
vector<int> ans(n);
int carry = 0;
for (int i = n - 1; i >= 0; i--) {
int dig = s[i] - '0';
if (carry == 0 && dig == 0) {
ans[i] = 1;
continue;
}
dig += carry;
if (dig == 1) {
ans[i] = 0;
carry = 0;
} else {
ans[i] = 11 - dig;
carry = 1;
}
}
for (int i : ans) {
cout << i;
}
cout << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}