列表

详情


NC213937. 仓鼠更有精神

描述


输入描述

输入描述见上

输出描述

输出描述见上

示例1

输入:

3
henyoujingshen 0
henyoujingshen 1
henyoujingshen 3

输出:

2
4
7

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++11) 解法, 执行用时: 560ms, 内存消耗: 1288K, 提交时间: 2020-11-27 19:30:44

#include"bits/stdc++.h"
using namespace std;
int n,k;
const int maxn=1e6+10;
char s[maxn];
bool ch(char c){
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') return true;
	return false;
}
int main()
{
	cin>>n;
	while(n--){
		cin>>s+1;
		cin>>k;
		int a1=0,k1=0,l=0;
		for(int i=1;i<=strlen(s+1);i++){
			if(ch(s[i])) a1=max(a1,i-l);
			else{
				k1++;
				while(k1>k){
					l++;
					if(!ch(s[l])) k1--;
				}
				a1=max(a1,i-l);
			}
		}
		cout<<a1<<endl;
	}
}

上一题