【编程题目 |100分】最长的指定瑕疵度的元音子串【2022 Q2考试题 2024 Q1考试题 C卷】


时间限制:C/C++ 1秒,其他语言 2秒

空间限制:C/C++262144K,其他语言524288K

64bit IO Format:%lld


本题可使用本地IDE编码,不能使用本地已有代码,无跳出限制,

编码后请点击”保存并调试“按钮进行代码提交。


题目描述

最长的指定瑕疵度的元音子串

开头和结尾都是元音字母(aeiouAEIOU)的字符串为元音字符串,其中混杂的非元音字母数量为其瑕疵度。比如:

  1. “a” 、 “aa”是元音字符串,其瑕疵度都为0
  2. “aiur”不是元音字符串(结尾不是元音字符)
  3.  “abira”是元音字符串,其瑕疵度为2

给定一个字符串,请找出指定瑕疵度的最长元音字符子串,并输出其长度,如果找不到满足条件的元音字符子串,输出0。

子串:字符串中任意个连续的字符组成的子序列称为该字符串的子串。

输入描述:

首行输入是一个整数,表示预期的瑕疵度flaw,取值范围[0, 65535]。

接下来一行是一个仅由字符a-z和A-Z组成的字符串,字符串长度(0, 65535]。

输出描述:

输出为一个整数,代表满足条件的元音字符子串的长度。


代码实现


C


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <bits/stdc++.h>
#define MAX_LEN 65536
struct Vowel {
int vNum;
int noVNum;
};
struct Vowel g_vowel[MAX_LEN];
#include <bits/stdc++.h> #define MAX_LEN 65536 struct Vowel { int vNum; int noVNum; }; struct Vowel g_vowel[MAX_LEN];
#include <bits/stdc++.h>

#define MAX_LEN 65536
struct Vowel {
    int vNum;
    int noVNum;
};
struct Vowel g_vowel[MAX_LEN];

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

C++解法一


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <bits/stdc++.h>
using namespace std;
int GetLongestFlawedVowelSubstrLen(const size_t flaw, const string &input)
{
int element[128] = {0};
string vowel("aeiouAEIOU");
for(char c:vowel)
element[c] = 1;
#include <bits/stdc++.h> using namespace std; int GetLongestFlawedVowelSubstrLen(const size_t flaw, const string &input) { int element[128] = {0}; string vowel("aeiouAEIOU"); for(char c:vowel) element[c] = 1;
#include <bits/stdc++.h>

using namespace std;

int GetLongestFlawedVowelSubstrLen(const size_t flaw, const string &input)
{
    int element[128] = {0};
    string vowel("aeiouAEIOU");
    for(char c:vowel)
        element[c] = 1;

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

C++解法二


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h> using namespace std;
#include<bits/stdc++.h>

using namespace std;

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

JAVA


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Scanner; public class Main {
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

JavaScript


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
let n = Number(readLine());
let str = readLine();
let n = Number(readLine()); let str = readLine();
let n = Number(readLine()); 
let str = readLine();

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

Python解法一


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
def longest_alp(degree, string):
vowel_string = "aeiouAEIOU"
head, length, tail = 0, 0, len(string) - 1
def longest_alp(degree, string): vowel_string = "aeiouAEIOU" head, length, tail = 0, 0, len(string) - 1
def longest_alp(degree, string):
    vowel_string = "aeiouAEIOU"
    head, length, tail = 0, 0, len(string) - 1

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

Python解法二


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
class Solution:
def longest_flawedvowel_substr_len(self, flaw, input_string):
left = 0
maxi = 0
class Solution: def longest_flawedvowel_substr_len(self, flaw, input_string): left = 0 maxi = 0
class Solution:
    def longest_flawedvowel_substr_len(self, flaw, input_string):
        left = 0
        maxi = 0

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

Python解法三


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
bct = "aeiou"
while 1:
try:
k = int(input())
nums = input()
bct = "aeiou" while 1: try: k = int(input()) nums = input()
bct = "aeiou"

while 1:
    try:
        k = int(input())
        nums = input()

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看