h*****d 发帖数: 295 | 1 用sas能做吗?
【 以下文字转载自 JobHunting 讨论区 】
发信人: duduhaha (starwithme), 信区: JobHunting
标 题: 分享一道最近碰到的很好的面试题。
发信站: BBS 未名空间站 (Thu Jan 27 21:32:45 2011, 美东)
给定字符串,求其不出现重复字符的子字符串的最大长度,如何测试。
比如,“abcabcbb”最大的就是“abc”长度3
“bbbbb”最大就是“b”长度1 |
d*******o 发帖数: 493 | 2 data test;
input char $1.@@;
cards;
abcabcbb
;
run;
proc sql;
select count(unique(char)) 'Num of character'
from test
;quit; |
e*******r 发帖数: 29 | 3 你做的是数出有多少个不同的字符,不是原题要的答案。比如在abbcbba中,
不同的字符有三个,但是最长的不同字符串长度为2.
【在 d*******o 的大作中提到】 : data test; : input char $1.@@; : cards; : abcabcbb : ; : run; : proc sql; : select count(unique(char)) 'Num of character' : from test : ;quit;
|
l*********s 发帖数: 5409 | |
l***a 发帖数: 12410 | 5 但是最长的不同字符串长度为2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~why? I didn't get that
【在 e*******r 的大作中提到】 : 你做的是数出有多少个不同的字符,不是原题要的答案。比如在abbcbba中, : 不同的字符有三个,但是最长的不同字符串长度为2.
|
k*****u 发帖数: 1688 | 6 abbcbba
ab then b, so length is 2; bc then b, length is 2; cb then b, length is 2;
ba lenth is 2;
so, for this string, the length is 2; but it has three chars: a b c.
that is it.
【在 l***a 的大作中提到】 : 但是最长的不同字符串长度为2 : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~why? I didn't get that
|
k*****u 发帖数: 1688 | 7 For string "abcabcbb", a naive way I thought is:
char pool length
a a 1
b ab 2
c abc 3
a a 1
b ab 2
c abc 3
b b 1
b b 1
so, at last the length is 3 |
w**********y 发帖数: 1691 | 8 google maximum subarray problem or Kadane's algorithm.
可以稍微改造写出一个O(n)的算法..
多年未用SAS了..依稀记得有scan这个函数..那么就可以遍历了...具体怎么写要问SAS
高人了...
【在 h*****d 的大作中提到】 : 用sas能做吗? : 【 以下文字转载自 JobHunting 讨论区 】 : 发信人: duduhaha (starwithme), 信区: JobHunting : 标 题: 分享一道最近碰到的很好的面试题。 : 发信站: BBS 未名空间站 (Thu Jan 27 21:32:45 2011, 美东) : 给定字符串,求其不出现重复字符的子字符串的最大长度,如何测试。 : 比如,“abcabcbb”最大的就是“abc”长度3 : “bbbbb”最大就是“b”长度1
|
f*******3 发帖数: 26 | 9 R很简单: length(unique(strsplit(x,"")[[1]])) |
d*******o 发帖数: 493 | 10 题目应该是找出重复的最大的子字串的长度。涉及到算法。SAS还是可以实现的。
【在 e*******r 的大作中提到】 : 你做的是数出有多少个不同的字符,不是原题要的答案。比如在abbcbba中, : 不同的字符有三个,但是最长的不同字符串长度为2.
|
j******o 发帖数: 127 | 11 这个方法是不是特别笨? 欢迎大家测试一下。假设事先知道给定字符的长度n。
%let n=20;
data have;
input str : $&n..;
datalines;
abcsdabcedbcsdaedfjs
;
run;
data have1;
set have;
do i=1 to &n;
do j=1 to &n-i;
sub=substr(str, i, j);
len=lengthn(sub);
output;
end;
output;
end;
run;
proc sort data=have1 nodupkey;
by i sub;
run;
proc sort data=have1;
by len sub;
run;
data have1;
set have1;
sub1=lag(sub);
if sub not eq sub1 then delete;
run;
data have1 (keep=str len);
set have1 end=last;
if last;
run; |
e****t 发帖数: 766 | 12 why abc, but not "bca" ? "cab" ?....
【在 h*****d 的大作中提到】 : 用sas能做吗? : 【 以下文字转载自 JobHunting 讨论区 】 : 发信人: duduhaha (starwithme), 信区: JobHunting : 标 题: 分享一道最近碰到的很好的面试题。 : 发信站: BBS 未名空间站 (Thu Jan 27 21:32:45 2011, 美东) : 给定字符串,求其不出现重复字符的子字符串的最大长度,如何测试。 : 比如,“abcabcbb”最大的就是“abc”长度3 : “bbbbb”最大就是“b”长度1
|