判断是否为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. Android中级教程之Android应用程序的生命周期

    Android应用程序的生命周期图 在大部分情况下,每个Android应用都将运行在自己的Linux进程中.当这个应用的某些代码需要执行时,进程就会被创建,并且将保持运行,直到该进程不再需要,而系统需 ...

  2. Louis Armstrong【路易斯·阿姆斯特朗】

    Louis Armstrong Louis Armstrong had two famous nicknames. 路易斯·阿姆斯特朗有两个著名的绰号. Some people called him ...

  3. HDU 6053 ( TrickGCD ) 分块+容斥

    TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  4. HDU 4005 The war 双连通分量 缩点

    题意: 有一个边带权的无向图,敌人可以任意在图中加一条边,然后你可以选择删除任意一条边使得图不连通,费用为被删除的边的权值. 求敌人在最优的情况下,使图不连通的最小费用. 分析: 首先求出边双连通分量 ...

  5. pycharm中某些方法被标黄的原因及解决办法

    在编辑python文件时,会遇到上图所示,函数方法被标黄的问题,但是不影响使用. 引起原因:,如果不报错说明,这是因为你配置的python解释器中有该方法,但是pycharm没有找到这个方法,即加载失 ...

  6. tomcat缓存

    问题描述: 一个用到struts2框架的web项目,由于在struts.xml中少配置了一个action,导致项目运行时报异常.将原本好的代码复旧,重启tomcat服务,第一次加载程序没问题,再刷新时 ...

  7. poj 2251 Dungeon Master 3维bfs(水水)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21230   Accepted: 8261 D ...

  8. Block Nested-Loop 和 Batched Key Access

    官方文档:https://dev.mysql.com/doc/refman/5.7/en/bnl-bka-optimization.html BNL和BKA是MySQL 表关联的两种关联算法 比如t1 ...

  9. iptables端口转发命令

    需求很简单,把本地81端口映射到8080端口上 1. 所有的81请求转发到了8080上.   1 # iptables -t nat -A PREROUTING -p tcp --dport 81 - ...

  10. 【bzoj3083】遥远的国度 树链剖分+线段树

    题目描述 描述zcwwzdjn在追杀十分sb的zhx,而zhx逃入了一个遥远的国度.当zcwwzdjn准备进入遥远的国度继续追杀时,守护神RapiD阻拦了zcwwzdjn的去路,他需要zcwwzdjn ...