ACPC Kickoff 2021

ACPC 2021比赛中的一道题目,要求求解给定字符串中两个不同字母的最大下标差。题解采用枚举和贪心策略,通过维护每个字母出现的最大和最小下标来找出最大间距。
摘要由CSDN通过智能技术生成

**Problem L. Memable Ace **

题意:
给出一个由小写字母构成的字符串(下标从0开始),需求出两个不同的字母相距的最大下标差是多少?

Input

The first line contains an integer T number of test cases where (1≤T≤10).
The only line in each test case is the string S consisting only of lowercase Latin letters where (2≤|S|≤105)

Output

For each test case print the maximum distance between a pair satisfying the above conditions.

知识点:
枚举,贪心

题解:
我们可以创建两个与26个字母对应的数组,用来储存这些字母下标的最大和最小值,之后嵌套遍历这两个数组得到距离的最大值。

代码:

#include <bits/stdc++.h>
 
using namespace std;
 // 创建数组
int mi[27];
int ma[27];
 
int main () {
   
    int tt;
    freopen
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pale_B

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值