zoukankan      html  css  js  c++  java
  • 水题 Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift

    题目传送门

     1 /*
     2     水题:vector容器实现插入操作,暴力进行判断是否为回文串
     3 */
     4 #include <cstdio>
     5 #include <iostream>
     6 #include <algorithm>
     7 #include <cstring>
     8 #include <string>
     9 #include <vector>
    10 using namespace std;
    11 
    12 const int MAXN = 1e4 + 10;
    13 const int INF = 0x3f3f3f3f;
    14 vector<char> s;
    15 char ss[11];
    16 
    17 bool check(void)
    18 {
    19     for (int i=0, j=s.size ()-1; i<j; ++i, --j)
    20         if (s[i] != s[j])    return false;
    21     return true;
    22 }
    23 
    24 int main(void)        //Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift
    25 {
    26     //freopen ("A.in", "r", stdin);
    27 
    28     while (cin >> ss)
    29     {
    30         s.clear ();    bool flag = false;
    31         for (int i=0; ss[i]; ++i)    s.push_back (ss[i]);
    32         for (int i=0; i<=s.size (); ++i)
    33         {
    34             for (int j=0; j<=26; ++j)
    35             {
    36                 char ch = 'a' + j;
    37                 s.insert (s.begin () + i, ch);
    38                 if (check ())
    39                 {
    40                     flag = true;
    41                     for (int i=0; i<s.size (); ++i)
    42                         cout << s[i];
    43                     cout << endl;    break;
    44                 }
    45                 else s.erase (s.begin () + i);
    46             }
    47             if (flag)    break;
    48         }
    49 
    50         if (!flag)    cout << "NA" << endl;
    51     }
    52 
    53     return 0;
    54 }
     1 #include <cstdio>
     2 #include <iostream>
     3 #include <algorithm>
     4 #include <cstring>
     5 #include <string>
     6 #include <vector>
     7 using namespace std;
     8 
     9 const int MAXN = 1e4 + 10;
    10 const int INF = 0x3f3f3f3f;
    11 
    12 bool ok(string x)
    13 {
    14     string ss = x;
    15     reverse (ss.begin (), ss.end ());
    16     return (ss == x);
    17 }
    18 
    19 int main(void)        //Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift
    20 {
    21     //freopen ("A.in", "r", stdin);
    22 
    23     string s;
    24     cin >> s;
    25 
    26     int len = s.size ();
    27     for (int i=0; i<=len; ++i)
    28     {
    29         for (char c='a'; c<='z'; ++c)
    30         {
    31             string x;
    32             for (int j=0; j<i; ++j)    x += s[j];
    33             x += c;
    34             for (int j=i; j<len; ++j)    x += s[j];
    35             if (ok (x))    {cout << x << endl;    return 0;}
    36         }
    37     }
    38     cout << "NA" << endl;
    39 
    40     return 0;
    41 }
    string 实现
    编译人生,运行世界!
  • 相关阅读:
    Java网络编程详解
    android 取mac若干问题
    android问题 This version of android studio is incompatible with the gradle version used.
    c#将DataTable内容导出为CSV文件
    C#下利用正则表达式实现字符串搜索功能的方法(转)
    C#正则表达式入门
    java 文件类 null与exists()是不一样的
    c#线程中下载文件到本地
    Git 常用命令
    Web 监听器
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4512383.html
Copyright © 2011-2022 走看看