CF1760B

题意

\(T\) 组数据,每次给定一个只含小写字母的字符串,求要拼出这个句子至少需要长度为多少的字母表。定义长度为 \(x\) 的字母表含有 \(26\) 字母表上的前 \(x\) 个字母。

做法

转化一下题目,很容易发现题目本质上就是要求字符串中最大的字母在 \(26\) 字母表中的位置。其它不是最大的字母也能出现在上面。因此实现就十分简单了。

Code

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int len,ans=0;
		string s;
		cin>>len;
		cin>>s;
		for(int i=0;i<len;i++)
			ans=max(ans,s[i]-96);
		cout<<ans<<endl;
	}
	return 0;
}
posted @ 2024-01-20 17:47  liyilang2021  阅读(8)  评论(0编辑  收藏  举报