首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【CodeForces】554A - Kyoya and Photobooks(思维)

【CodeForces】554A - Kyoya and Photobooks(思维)

作者头像
FishWang
发布2025-08-26 20:18:18
发布2025-08-26 20:18:18
10500
代码可运行
举报
运行总次数:0
代码可运行

A. Kyoya and Photobooks

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?

Please help Haruhi solve this problem.

Input

The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters.

Output

Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.

Examples

input

代码语言:javascript
代码运行次数:0
运行
复制
a

output

代码语言:javascript
代码运行次数:0
运行
复制
51

input

代码语言:javascript
代码运行次数:0
运行
复制
hi

output

代码语言:javascript
代码运行次数:0
运行
复制
76

Note

In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.

题意,插入一个字母,可以和给出的字母相同,求最多有多少种插法。

题解:代码分几个模块:

①求插入的字母和已知字母不同的方案数,也是最简单的。

②插入的字母和已知字母(只出现一次)相同的方案数。

③插入已知字母中多次出现(> 1)的方案数,这一种就依次取要插入的字母和上次插入的比较,不同则方案数加一。(队友小企鹅的贡献)

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
int main()
{
	char a[30];
	int l;
	int num[27];
	char b[30];		//重复字母 
	int ans;
	while (~scanf ("%s",a))
	{
		memset (num,0,sizeof (num));
		memset (b,'0',sizeof (b));
		l = strlen (a);
		for (int i = 0 ; i < l ; i++)
			num[a[i] - 'a' + 1]++;
		int ant1 = 0;		//多少个字母
		int ant2 = 0;		//多少个重复字母
		for (int i = 1 ; i <= 26 ; i++)
		{
			if (num[i] == 1)
				ant1++;
			if (num[i] > 1)
			{
				ant1++;
				b[ant2++] = 'a' + i - 1;
			}
		}
		ans = (26 - ant1) * (l + 1);		//插入不重复字母
		ans += (ant1 - (ant2)) * l;		//只出现一次的字母
		//......待填坑 
		int sum=0,s;
		char ch[5];
		for (int i = 0 ; i < ant2 ; i++)
		{
			s=1;
			ch[1] = b[i];
			ch[2] = a[0];
			for (int j=0;j<l;j++)
			{
				ch[3] = a[j];
				ch[4] = b[i];
				if (ch[3] != ch[1] || ch[2] != ch[4])
					s++;
				//重新赋值 
				ch[1] = b[i];
				ch[2] = a[j+1];
			}
			sum += s;
		}
		ans += sum;
		printf ("%d\n",ans);
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档