zoukankan      html  css  js  c++  java
  • 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');
                else
                    s1=s.substr(0,i)+char(j+'a')+s.substr(i,s.size());
                if(!H[s1])
                {
                    ans++;
                    H[s1]=1;
                }
            }
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    problem report: middle of linked list
    Partition List解题报告
    Reverse Linked List解题报告
    Remove Duplicates from Sorted List解题报告
    strStr解题报告
    各种编码之间的关系以及getBytes的使用
    jsp/servlet中的编码问题
    javabean+servlet+jsp实现分页
    ligerUI实现分页
    java实现的简单词法分析器
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4599068.html
Copyright © 2011-2022 走看看