String Play

Milo has a string S of length L. Tutu picks a random prefix and Mota picks a random suffix ofS.

Now, Chotku is given a task of concatenating the two strings that Tutu and Mota have chosen, in respective order. Chotku wonders, how many distinct prefix-suffix concatenation is possible out there of string S.

So you know what to do.. Help Chotku!

Input

Input file contains several lines of text. Each line contains a string, S. End of file marks the end of input.

Output

Output one integer per string, denoting the number of distinct prefix-suffix concatenation of the string.

Constraints

  1. Strings consist of lower-case letters only.

  2. 1 ≤ L ≤ 10000006

Sample Input

Output for Sample Input

abc
aab

8
7

Explanation:

For sample #1, the 3 prefixes are “a”, “ab”, “abc”

The 3 suffixes are “c”, “bc”, “abc”

And the 8 distinct concatenations are, “ac”, “abc”, “aabc”, “abbc”, “ababc”, “abcc”, “abcbc”, “abcabc”.

题意:一个字符串,A取一段前缀,B取一段后缀,然后连接起来组成一个新的字符串S,问可以组成多少种新的字符串,重复的只统计一次。

思路:首先必须是O(n)的复杂度,然后我什么都不知道了。

#include<bits/stdc++.h>
const int maxn=;
using namespace std;
char c[maxn]; int num[];
int main()
{
int Len,i; long long ans;
while(~scanf("%s",c+)){
Len=strlen(c+); ans=Len;
memset(num,,sizeof(num));
for(i=;i<=Len;i++) num[c[i]-'a']++;
for(i=Len-;i>=;i--){
ans+=Len-num[c[i+]-'a'];
if(c[i+]==c[Len]) ans++;
}
printf("%lld\n",ans);
}
return ;
}

SPOJ:String Play (?)的更多相关文章

  1. 【Java】Java创建String时,什么情况放进String Pool?

    对Java创建String是否放入String pool作代码性的试验. 参考的优秀文章 JAVA面试题解惑系列(二)——到底创建了几个String对象? public String(String o ...

  2. Date类为什么设计为可变的,而不是像String一样?

    首先,不得不承认,这确实是类库设计的一个错误,所以"为什么"进行了这个错误设计并没有意义.但没有事物一诞生就是完美的,我们的Java只是反应的慢了一点,再慢了一点. 更何况,Dat ...

  3. 你真的了解String吗?(修正版)

    修正前:new出来的对象,会在堆中存放真正的值: 大错特错!!!! 修正后:new出来的对象,堆存放的并不是真正的值,而是常量池中字符串常量的地址. 一.抛砖引玉 ​ 不知道大家在做面试题时是否会遇到 ...

  4. 众所周知,static修饰的成员只实例化一次,而string类型每次赋值都会重新创建一个实例,那么用static修饰string呢?

    string 类型每次实例化都会重新创建一个实例: 解释:string 类型重载了运算符 “=” ,每次 “=” 操作都是一次 “new”. static 修饰符的成员只实例化一次?? 解释:这个说法 ...

  5. .NET中的字符串(2):你真的了解.NET中的String吗?

    概述 String在任何语言中,都有它的特殊性,在.NET中也是如此.它属于基本数据类型,也是基本数据类型中唯一的引用类型.字符串可以声明为常量,但是它却放在了堆中.希望通过本文能够使大家对.NET中 ...

  6. StringBuilder 比 String 快?空嘴白牙的,证据呢!

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 聊的是八股的文,干的是搬砖的活! 面我的题开发都用不到,你为什么要问?可能这是大部分 ...

  7. 你,确定了解Java的String字符串?

    本文将描述JDK6中String.intern()是如何实现的,以及在JDK7和JDK8中对字符串池化技术做了哪些改变. String池化介绍 String池化就是把一些值相同,但是标识符不同的字符串 ...

  8. 在aspx怎么引用public string getPicurl(string picurl)?

    刚才在论坛上看到一帖: Insus.NET尝试做了一下,直接使用一个Img标签是无法实现.因为函数中返回的即是一个img html标签,因此在aspx页再不能使用Img了. 现在可以回到网友的问题,那 ...

  9. JavaScript中如何检测一个变量是一个String类型?

    typeof x === "string" typeof(x) === "string' // 小写 x.constructor === String // 大写类型 同 ...

随机推荐

  1. go1.11新特性,mark一下

    包管理新特性: export GO111MODULE=on #开启modules go mod init # 创建go.mod (我是在项目根目录下输入的命令) ls // 可以看下创建成功 cat ...

  2. (2)git本地生成SSH关联github

    1.安装git 2.打开 Git Bash 输入ssh ,查看是否安装了ssh 这个界面是安装了的意思 3.生成ssh 输入ssh-keygen -t rsa 指令, 再连续按三次回车 会生成两个文件 ...

  3. Codeforces 735 E Ostap and Tree

    Discription Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his ga ...

  4. Atcoder 3857 Median Sum

    Problem Statement You are given N integers A1, A2, ..., AN. Consider the sums of all non-empty subse ...

  5. Codeforces 837 E Vasya's Function

    Discription Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) =  ...

  6. spring boot 文件上传大小配置

    在启动类中,添加bean import javax.servlet.MultipartConfigElement; import org.springframework.boot.SpringAppl ...

  7. JS---数组(Array)处理函数整理

    1.concat() 连接两个或更多的数组该方法不会改变现有的数组,而仅仅会返回被连接数组的一个副本.例如: 代码如下: <script type="text/javascript&q ...

  8. 改动C:\WINDOWS\system32\drivers\etc\hosts 文件有什么作用

    host是一个没有扩展名的系统文件,能够用记事本等工具打开,其作用就是将一些常常使用的网址域名与其相应的IP地址建立一个关联"数据库".当用户在浏览器中输入一个须要登录的网址时,系 ...

  9. Redhat7/centOs7 安装配置python3.6.5

    centos默认安装python2,设置py2和py3并存的方法如下: sudo yum install openssl-devel -y sudo yum install zlib-devel -y ...

  10. XStream 数组(List)输出结构

    <!-- 期望的DOM树 --> <Articles> <item> <Title>微信SDK初步结构</Title> <Descri ...