Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
A. Kyoya and Photobooks
Time Limit: 20 Sec
Memory Limit: 256 MB
題目連接
http://codeforces.com/contest/554/problem/A
Description
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.
Sample Input
a
Sample Output
51
HINT
?
題意
給你一個字符串,然后讓你隨便在一個位置加上一個字母,問你能夠產生多少個不同的字符串
題解:
暴力加字符串,然后用map判重就好了
代碼
?
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 200001 #define mod 10007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; /*inline void P(int x) {Num=0;if(!x){putchar('0');puts("");return;}while(x>0)CH[++Num]=x%10,x/=10;while(Num)putchar(CH[Num--]+48);puts(""); } */ inline ll read() {int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } inline void P(int x) {Num=0;if(!x){putchar('0');puts("");return;}while(x>0)CH[++Num]=x%10,x/=10;while(Num)putchar(CH[Num--]+48);puts(""); } //************************************************************************************** map<string,int> H;int main() {string s;cin>>s;int ans=0;for(int i=0;i<=s.size();i++){for(int j=0;j<26;j++){string s1;if(i==0)s1=char(j+'a')+s;else if(i==s.size())s1=s+char(j+'a');elses1=s.substr(0,i)+char(j+'a')+s.substr(i,s.size());if(!H[s1]){ans++;H[s1]=1;}}}cout<<ans<<endl; }?
轉載于:https://www.cnblogs.com/qscqesze/p/4599068.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php的session实现
- 下一篇: (转)Linux grep