判断是否为n回文,比如 a b a 是1 回文, abcdab是2回文。

输入: abcabc|3 这种格式,输出true or false

#include <iostream>
#include <string>
#include <sstream>
using namespace std; bool judge_n_pal(string str,int n)
{
if(str.empty() || n <= || str.size()%n != )
return false; int i = ;
int j = str.size()-n;
while(i<j)
{
for(int p = ; p < n;p++)
{
if(str[i+p] != str[j+p])
return false;
}
i = i + n;
j = j - n;
}
return true;
}
int main()
{
string input;
cin>>input; string content;
int x = input.find_first_of('|');
content = input.substr(,x); int n;
string str_n = input.substr(x+,input.length()-x-);
stringstream(str_n)>>n; bool ret = judge_n_pal(content,n);
cout<<input<<" "<<ret;
}

interview ms1 N_Dorm的更多相关文章

  1. interview ms1 robert move **

    move 2turn rightmove 3turn rightmove 6 初始位置为(0,0),方向为north,求最后的位置. string2char:  const char* t = sec ...

  2. Pramp mock interview (4th practice): Matrix Spiral Print

    March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...

  3. WCF学习系列二---【WCF Interview Questions – Part 2 翻译系列】

    http://www.topwcftutorials.net/2012/09/wcf-faqs-part2.html WCF Interview Questions – Part 2 This WCF ...

  4. WCF学习系列一【WCF Interview Questions-Part 1 翻译系列】

    http://www.topwcftutorials.net/2012/08/wcf-faqs-part1.html WCF Interview Questions – Part 1 This WCF ...

  5. Amazon Interview | Set 27

    Amazon Interview | Set 27 Hi, I was recently interviewed for SDE1 position for Amazon and got select ...

  6. Java Swing interview

    http://www.careerride.com/Swing-AWT-Interview-Questions.aspx   Swing interview questions and answers ...

  7. Pramp - mock interview experience

    Pramp - mock interview experience   February 23, 2016 Read the article today from hackerRank blog on ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. [译]Node.js Interview Questions and Answers (2017 Edition)

    原文 Node.js Interview Questions for 2017 什么是error-first callback? 如何避免无止境的callback? 什么是Promises? 用什么工 ...

随机推荐

  1. Network of Schools POJ - 1236 (强联通)

    一些学校连接到了一个计算机网络.网络中的学校间有如下约定:每个学校维护一个列表,当该学校收到软件或信息后将会转发给列表中的所有学校(也就是接收方列表).需要注意的是如果B学校在A学校的接收方列表中,A ...

  2. 17,基于scrapy-redis两种形式的分布式爬虫

    redis分布式部署 1.scrapy框架是否可以自己实现分布式? - 不可以.原因有二. 其一:因为多台机器上部署的scrapy会各自拥有各自的调度器,这样就使得多台机器无法分配start_urls ...

  3. Retrofit 入门和提高

    首先感谢这个哥们,把我从helloworld教会了. http://blog.csdn.net/angcyo/article/details/50351247 retrofit 我花了两天的时间才学会 ...

  4. Android事件分发机制浅析(3)

    本文来自网易云社区 作者:孙有军 我们只看最重要的部分 1: 事件为ACTION_DOWN时,执行了cancelAndClearTouchTargets函数,该函数主要清除上一次点击传递的路径,之后执 ...

  5. Windows下Eclipse安装PyDev

    事后证明PyDev不好用,推荐使用pycharm!!!   1.安装eclipse,这个网上一大堆,就不说了 2.安装python,这个网上一大堆,就不说了 3.Eclipse安装PyDev 第一种在 ...

  6. Feign请求报请求超时

    Feign的底层基于Rabbion实现的,一般情况下直接导入feign的依赖,然后调用feignClient去发送请求,报请求超时. application.yml #hystrix的超时时间 hys ...

  7. Python+selenium(警告框处理)

    在Webdriver中处理JavaScript生成的alert.confirm.prompt,使用switch_to_alert()方法定位到alert.confirm.prompt,然后进行如下操作 ...

  8. PostgreSQL查看索引的使用情况

    查看某个表的索引使用情况 select relname, indexrelname, idx_scan, idx_tup_read, idx_tup_fetch from pg_stat_user_i ...

  9. dijkstra 堆优化

    #include <iostream> #include <vector> #include <cstring> #include <queue> us ...

  10. Java精确测量代码运行时间 代码执行时间 纳秒 nanoTime

      Java精确测量代码运行时间:         long startTime = System.nanoTime();  //開始時間         for(int i = 0;i<100 ...