zoukankan      html  css  js  c++  java
  • Codeforces Round #286 (Div. 2)A. Mr. Kitayuta's Gift(暴力,string的应用)

    由于字符串的长度很短,所以就暴力枚举每一个空每一个字母,出现行的就输出。这么简单的思路我居然没想到,临场想了很多,以为有什么技巧,越想越迷。。。是思维方式有问题,遇到问题先分析最简单粗暴的办法,然后一步一步的优化,不能盲目的想。

    这道题要AC的快需要熟悉string的各种用法。这里做个简单总结:C++中string的常见用法

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<map>
    #include<set>
    #include<vector>
    #include<algorithm>
    #include<stack>
    #include<queue>
    #include<cctype>
    #include<sstream>
    using namespace std;
    #define pii pair<int,int>
    #define LL long long int
    const int eps=1e-8;
    const int INF=1000000000;
    const int maxn=0;
    bool yes(string ss)
    {
        string ss2=ss;
        reverse(ss.begin(),ss.end());
        return ss==ss2;
    }
    string sstr,ans;
    int main()
    {
        //freopen("in2.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        cin>>sstr;
        int n=sstr.length();
        for(int i=0;i<=n;i++)
        {
            for(char ch='a';ch<='z';ch++)
            {
                ans=sstr;
                ans.insert(ans.begin()+i,ch);
                if(yes(ans))
                {
                    cout<<ans<<endl;
                    return 0;
                }
            }
        }
        cout<<"NA"<<endl;
        //fclose(stdin);
        //fclose(stdout);
        return 0;
    }
  • 相关阅读:
    第一次个人编程作业
    第一次博客作业
    动态规划 01背包学习中
    学习dijk最短路径中
    蓝桥杯 小盆友排队
    蓝桥杯 地宫取宝
    简单的BFS学习笔记
    C趣味100道之58.拉丁方的一些想法。
    蓝桥杯 错误票据--!偶然间发现,然后呵呵!
    函数实现计算标准差
  • 原文地址:https://www.cnblogs.com/zywscq/p/4236600.html
Copyright © 2011-2022 走看看