zoukankan      html  css  js  c++  java
  • Codeforces 505 A Mr. Kitayuta's Gift【暴力】

    题意:给出一个字符串,可以向该字符串的任意位置插入一个字母使其变成回文串

    因为字符串的长度小于10,枚举插入的字母,和要插入的位置,再判断是否已经满足回文串

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<set>
     9 #include<queue> 
    10 #include<algorithm>  
    11 using namespace std;
    12 
    13 typedef long long LL;
    14 const int INF = (1<<30)-1;
    15 const int mod=1000000007;
    16 const int maxn=100005;
    17 char t[15],s[15];
    18 int n;
    19 
    20 bool is(){
    21     for(int l=0,r=n;l<r;l++,r--){
    22         if(t[l]!=t[r])
    23         return false;
    24     }
    25     return true;
    26 }
    27 
    28 int main(){
    29     cin>>s;
    30     n=strlen(s);
    31     for(char ch='a';ch<='z';ch++){//枚举那个要被替换的字母 
    32         
    33         for(int i=0;i<=n;i++){ //枚举插入的位置 
    34              int len=0; 
    35              
    36              for(int j=0;j<i;j++) t[len++]=s[j];
    37              t[len++]=ch;
    38              for(int j=i;j<n;j++) t[len++]=s[j];
    39              if(is()) {
    40              printf("%s
    ",t);
    41              return 0;
    42              }    
    43         }
    44     }
    45     printf("NA
    ");
    46     return 0;
    47 }
    View Code
  • 相关阅读:
    15 手写数字识别-小数据集
    14 深度学习-卷积
    13-垃圾邮件分类2
    12.朴素贝叶斯-垃圾邮件分类
    11.分类与监督学习,朴素贝叶斯分类算法
    9、主成分分析
    7.逻辑回归实践
    8.特征选择,过滤式
    6.逻辑回归
    5.线性回归算法
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4436445.html
Copyright © 2011-2022 走看看