由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - [转载] CS Interview question
相关主题
请教palindrome算法C ++ 问题
一道C++面试题来,做题吧。
how to check if two palindromes are unique?python3 输入 菜鸟问题
有人做过ITA的考试题吗?为什么用try catch不住exception?
请教一个字符串比较排序的问题问一个MinGW + CMake 的问题
char *p = "string literal"; 和 char a[] = "string liter (转载)菜鸟的苹果编程问题
出个题考考大家:)Windows多媒体编程入门问题
Array in CVISUAL STUDIO 2005 输出窗口(output) 怎么找不到?
相关话题的讨论汇总
话题: returns话题: string话题: cs话题: interview
进入Programming版参与讨论
1 (共1页)
l***t
发帖数: 81
1
【 以下文字转载自 JobHunting 讨论区 】
【 原文由 lhict 所发表 】
Create a function findPalin() that takes a string of characters as argument
and returns the number of palindromes (a string in which the sequence of cha
racters is the same forwards and backwards) in that string. There is no spec
ial character. This function should be as fast as possible.
Ex:
"aa" returns 1
"aabb" returns 2
"222" returns 3
"baaab3" returns 4
n******t
发帖数: 4406
2
First We need to define maximum palindrome, which means it is a palindrom
but any extension on both side will not make a palindrome.
for every such a palindrome with length k has child palindromes
of number k/2. So what we need to do is to find all the maxium palindromes.
To do this reverse the string S to S'.We say that such palindromes must
appears in S'. And further because it is maximum, so suppose it starts from
i and end in j with m the middle of it. so S(i-1)!=S(j+1), that means it
is the

【在 l***t 的大作中提到】
: 【 以下文字转载自 JobHunting 讨论区 】
: 【 原文由 lhict 所发表 】
: Create a function findPalin() that takes a string of characters as argument
: and returns the number of palindromes (a string in which the sequence of cha
: racters is the same forwards and backwards) in that string. There is no spec
: ial character. This function should be as fast as possible.
: Ex:
: "aa" returns 1
: "aabb" returns 2
: "222" returns 3

b*****e
发帖数: 474
3
Let's say that the input string is S, S[1]..S[N] are the chars.
The question is to find all pairs (i,j) such that:
1) i 2) S[i+k] == S[j-k] for all k=0 to j-i. (actually to (j-i)/2 is sufficient.)
b*****e
发帖数: 474
4

This is A[i][i+1], not A[i][j+1]. (S[i]==S[i+1] means same adjacent chars,
obviously a palin.)
That's why there is a "probably". :)

【在 n******t 的大作中提到】
: First We need to define maximum palindrome, which means it is a palindrom
: but any extension on both side will not make a palindrome.
: for every such a palindrome with length k has child palindromes
: of number k/2. So what we need to do is to find all the maxium palindromes.
: To do this reverse the string S to S'.We say that such palindromes must
: appears in S'. And further because it is maximum, so suppose it starts from
: i and end in j with m the middle of it. so S(i-1)!=S(j+1), that means it
: is the

P***t
发帖数: 1006
5
我的程序和你的很象,不过我是这么想的:
对一个字符串,从左到右,分别以某个字符(或两个字符的中间)为轴,
然后向两边找对应字符,看看最远能走多少。加起来就是了。
如 “222"
2|2 2
2|2|2
2 2|2
#ifdef WIN32
#pragma warning(disable:4786 4101)
#define min _MIN
#define max _MAX
#endif
#include
#include
#include
using namespace std;
int maxPalindrome(string s)
{
int i, j, k;
int count = 0;
for(i = 0; i < s.size(); i++)
for(k = 0; k < 2; k++)
for(j = 1; ; j++)
{
int x1 = i + k + j;


【在 b*****e 的大作中提到】
: Let's say that the input string is S, S[1]..S[N] are the chars.
: The question is to find all pairs (i,j) such that:
: 1) i: 2) S[i+k] == S[j-k] for all k=0 to j-i. (actually to (j-i)/2 is sufficient.)

n******t
发帖数: 4406
6
是字符操作.不是字符串操作.一般的Ram model.
这个算法主要是建立在suffix tree的处理能力上面.
在建立好suffix tree之后(linear time), 对于每个
LCE的应答在常数时间内可以完成.有兴趣可以查查
suffix tree的算法.

【在 P***t 的大作中提到】
: 我的程序和你的很象,不过我是这么想的:
: 对一个字符串,从左到右,分别以某个字符(或两个字符的中间)为轴,
: 然后向两边找对应字符,看看最远能走多少。加起来就是了。
: 如 “222"
: 2|2 2
: 2|2|2
: 2 2|2
: #ifdef WIN32
: #pragma warning(disable:4786 4101)
: #define min _MIN

1 (共1页)
进入Programming版参与讨论
相关主题
VISUAL STUDIO 2005 输出窗口(output) 怎么找不到?请教一个字符串比较排序的问题
About Longest repeated substringchar *p = "string literal"; 和 char a[] = "string liter (转载)
C++ string类输入数据的问题出个题考考大家:)
C下有没有好用的hash table函数库?Array in C
请教palindrome算法C ++ 问题
一道C++面试题来,做题吧。
how to check if two palindromes are unique?python3 输入 菜鸟问题
有人做过ITA的考试题吗?为什么用try catch不住exception?
相关话题的讨论汇总
话题: returns话题: string话题: cs话题: interview