interview ms1 N_Dorm
判断是否为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的更多相关文章
- interview ms1 robert move **
move 2turn rightmove 3turn rightmove 6 初始位置为(0,0),方向为north,求最后的位置. string2char: const char* t = sec ...
- 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 ...
- WCF学习系列二---【WCF Interview Questions – Part 2 翻译系列】
http://www.topwcftutorials.net/2012/09/wcf-faqs-part2.html WCF Interview Questions – Part 2 This WCF ...
- WCF学习系列一【WCF Interview Questions-Part 1 翻译系列】
http://www.topwcftutorials.net/2012/08/wcf-faqs-part1.html WCF Interview Questions – Part 1 This WCF ...
- Amazon Interview | Set 27
Amazon Interview | Set 27 Hi, I was recently interviewed for SDE1 position for Amazon and got select ...
- Java Swing interview
http://www.careerride.com/Swing-AWT-Interview-Questions.aspx Swing interview questions and answers ...
- Pramp - mock interview experience
Pramp - mock interview experience February 23, 2016 Read the article today from hackerRank blog on ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- [译]Node.js Interview Questions and Answers (2017 Edition)
原文 Node.js Interview Questions for 2017 什么是error-first callback? 如何避免无止境的callback? 什么是Promises? 用什么工 ...
随机推荐
- Spark架构与作业执行流程简介(scala版)
在讲spark之前,不得不详细介绍一下RDD(Resilient Distributed Dataset),打开RDD的源码,一开始的介绍如此: 字面意思就是弹性分布式数据集,是spark中最基本的数 ...
- A1058 A+B in Hogwarts (20)(20 分)
A1058 A+B in Hogwarts (20)(20 分) If you are a fan of Harry Potter, you would know the world of magic ...
- layer父页面调用子页面的方法
由于不知道如何在子页面获取到layer定义的确定按钮,于是就在子页面上定义了一个方法,然后在由父页面在点确定按钮时调用子页面所定义的这个方法,从而执行子页面方法里面的内容: 子页面代码: functi ...
- “帮你APP”团队冲刺3
1.整个项目预期的任务量 (任务量 = 所有工作的预期时间)和 目前已经花的时间 (所有记录的 ‘已经花费的时间’),还剩余的时间(所有工作的 ‘剩余时间’) : 所有工作的预期时间:88h 目前已经 ...
- 通过js date对象获取各种开始结束日期的示例
有时候做一些任务计划的功能时候,需要提供一个开始时间或者结束时间,比如本周结束,本月结束,今天结束等等,因此,我参考网上的资料把相关的实现为一个项目: gitee: https://gitee.com ...
- 59、佳博wifi打印机怎么配置
1.去这里下载配置软件(注意,需要再windows下进行)http://pan.baidu.com/s/1bn1y4FX,并解压安装程序 2.连上wifi打印机的热点,比如说佳博打印机的默认为Gpri ...
- PyInstaller打包python脚本
用python写的工具写好了,想打包然后发给测试同事使用,最后选择了PyInstaller,支持Windows.Linux.OS X,支持打包成一个文件夹或单个EXE文件. 我是直接在线安装的,在 ...
- Java的移位运算符
1.左移运算符:<< 丢弃左边指定位数,右边补0. 注意: 当int类型进行左移操作时,左移位数大于等于32位操作时,会先求余(%)后再进行左移操作.也就是说左移32位相当于不进行移位操作 ...
- Python之实现不同版本线程池
1.利用queue和threading模块可以实现多个版本的线程池,这里先贴上一个简单的 import queue import time import threading class ThreadP ...
- webpack vue-cli 常见问题总结
1. webpack打包压缩 ES6 js..vue报错: ERROR in js/test.js from UglifyJs Unexpected token punc ?(?, expected ...