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? 用什么工 ...
随机推荐
- 学习Pytbon第七天,集合
list_1=[5,22,2,6,5,66,6,8] list_1=set(list_1)#把列表转成集合,天生不允许 重复 print(list_1,type(list_1) list_2=set( ...
- 51NOD 1292 1277(KMP算法,字符串中的有限状态自动机)
在前两天的CCPC网络赛中...被一发KMP题卡了住了...遂决定,哪里跌倒就在哪里爬起来...把个KMP恶补一发,连带着把AC自动机什么的也整上. 首先,介绍设定:KMP算法计划解决的基本问题是,两 ...
- Java开发经验
两个类要传递参数: 1.构造方法 2.方法的参数 3.静态的变量
- Redis实现之字典跳跃表
跳跃表 跳跃表是一种有序数据结构,它通过在每个节点中维持多个指向其他节点的指针,从而达到快速访问节点的目的.跳跃表支持平均O(logN).最坏O(N)的时间复杂度查找,还可以通过顺序性操作来批量处理节 ...
- HBase官方文档
HBase官方文档 目录 序 1. 入门 1.1. 介绍 1.2. 快速开始 2. Apache HBase (TM)配置 2.1. 基础条件 2.2. HBase 运行模式: 独立和分布式 2.3. ...
- IOS开发学习笔记022-imageView实现动画
这里要播放的动画是很多张连续的动画,连续播放就会显示出动画效果. 大概过程是: 新建一个single view application ,然后添加一个image View控件到视图.给image vi ...
- Python面向对象之什么是类(1)
1.C#.Java :只能用面向对象编程 Ruby.Python :函数编程+ 面向对象 面向对象编程不是在所有地方都比函数式编程方便的,类是为了封装,下面是简单的使用方法 在创建类的时候要用clas ...
- HDU5862 Counting Intersections
Given some segments which are paralleled to the coordinate axis. You need to count the number of the ...
- c++中读取文件最快的方法
https://www.byvoid.com/blog/fast-readfile 可以看看了.
- [错误解决]ubuntu 不在 sudoers 文件中。此事将被报告。
跟据报错判断,ubuntu没有sudo权限,经过查询需要将ubuntu账户加入/etc/sudoers中 先切换到root权限 su 输入密码 修改/etc/sudoers配置 vim /etc/su ...