判断是否为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. Paul Zindel【保罗·金代尔】

    Paul Zindel Paul Zindel's death on March 27, 2003 ended the brilliant life of a famous write. 2003年3 ...

  2. STM32位带操作

    STM32的位带操作是基于cortex内核自带的,而不是st公司独创.基本的思路就是用一个32位的地址空间访问一个bit,因为stm32只支持32位数据的读取,不像51单片机一样,是可以单独对一位操作 ...

  3. 4 Values whose Sum is 0 POJ - 2785

    4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 29243   Accep ...

  4. POJ 2763 Housewife Wind 树链拋分

    一.前言 这破题WA了一天,最后重构还是WA,最后通过POJ讨论版得到的数据显示,我看上去是把某个变量写错了..于是,还是低级错误背锅啊....代码能力有待进一步提升2333333 二.题意 某家庭主 ...

  5. volatile、synchronized、lock有什么区别,以及在哪些场景下使用哪种方式?

    [转]JVM锁机制volatile/synchronized/lock 1.volatile实现原理 (1)聊聊并发(一)——深入分析Volatile的实现原理 --硬件级别锁实现,Lock前缀指令会 ...

  6. P3116 [USACO15JAN]会议时间Meeting Time

    P3116 [USACO15JAN]会议时间Meeting Time 题目描述 Bessie and her sister Elsie want to travel from the barn to ...

  7. hnust hold不住的老师

    问题 H: Hold不住的老师 时间限制: 1 Sec  内存限制: 128 MB提交: 415  解决: 63[提交][状态][讨论版] 题目描述 因为我们学校ACM集训队取得的一个个优异成绩,AC ...

  8. linux批量匹配移动文件的方法

    需求 有需要移动的文件名清单 filename.txt filename.txt 内容如下: 15542842 1582457 1282427 1532158 4542457 1582453 6552 ...

  9. VS 2013插件

    http://www.spersky.com/post/vsPlugins.html http://vswebessentials.com/download http://developer.51ct ...

  10. windows系统——U 盘损坏修复

    u盘损坏怎么修复 1.打开控制面板——管理工具——计算机管理——存储——磁盘管理——右击“磁盘1”——点击“初始化磁盘”——“确定”——初始化完毕后,U盘为“联机”状态. 2.在右边空白处“新建磁盘分 ...