D*******l 发帖数: 5462 | 1 In any programming language, create an input that accepts “My name is
Albert McDonald.” and outputs the reversed value “Ym eman si Trebla
DlAnodcm.” |
g*********e 发帖数: 14401 | |
k****0 发帖数: 7 | 3 challenge accepted!
python, complexity O(N)
def reorder(input_str):
case_queue = list()
letter_stack = list()
output = list()
for i in input_str:
if i in (" ", "."):
while letter_stack:
case = case_queue.pop(0)
letter = letter_stack.pop()
output.append(letter.upper() if case else letter.lower())
output.append(i)
else:
case_queue.append(1 if i.isupper() else 0)
letter_stack.append(i)
return "".join(output) |
w**z 发帖数: 8232 | 4 刚准备面试,换工作?这种题,不会有人再问了。
【在 D*******l 的大作中提到】 : In any programming language, create an input that accepts “My name is : Albert McDonald.” and outputs the reversed value “Ym eman si Trebla : DlAnodcm.”
|
w**z 发帖数: 8232 | 5 刚准备面试,换工作?这种题,不会有人再问了。
【在 D*******l 的大作中提到】 : In any programming language, create an input that accepts “My name is : Albert McDonald.” and outputs the reversed value “Ym eman si Trebla : DlAnodcm.”
|
b*******s 发帖数: 5216 | 6 这么简单的问题
【在 D*******l 的大作中提到】 : In any programming language, create an input that accepts “My name is : Albert McDonald.” and outputs the reversed value “Ym eman si Trebla : DlAnodcm.”
|
t****t 发帖数: 6806 | 7 作业不会做了还是面试题不会做了?
【在 D*******l 的大作中提到】 : In any programming language, create an input that accepts “My name is : Albert McDonald.” and outputs the reversed value “Ym eman si Trebla : DlAnodcm.”
|
n******7 发帖数: 12463 | |
a*****e 发帖数: 1700 | 9 标点不算在word里面。还有什么catch最好一次说清楚啊
【在 D*******l 的大作中提到】 : In any programming language, create an input that accepts “My name is : Albert McDonald.” and outputs the reversed value “Ym eman si Trebla : DlAnodcm.”
|
n*****t 发帖数: 22014 | 10 dst = [];
src.split(/s+/).forEach(function(x) { dst.push(x.split("").reverse().join(''
))});
console.log(dst.join(' '))
【在 D*******l 的大作中提到】 : In any programming language, create an input that accepts “My name is : Albert McDonald.” and outputs the reversed value “Ym eman si Trebla : DlAnodcm.”
|
|
|
t****t 发帖数: 6806 | 11 你这题都没看清楚吧...
''
【在 n*****t 的大作中提到】 : dst = []; : src.split(/s+/).forEach(function(x) { dst.push(x.split("").reverse().join('' : ))}); : console.log(dst.join(' '))
|
n*****t 发帖数: 22014 | 12 大小写跟句号?这题毫无趣味,懒得改了,LOL
【在 t****t 的大作中提到】 : 你这题都没看清楚吧... : : ''
|
l*******e 发帖数: 309 | 13 import Data.Char
import Control.Applicative
main = interact $ same_case <*> (unwords . map reverse' . words)
where reverse' word = if isPunctuation (last word)
then reverse (init word) ++ [last word]
else reverse word
same_case = zipWith (\x y -> if isUpper x then toUpper y else
toLower y) |
m*********a 发帖数: 3299 | 14 #include
#include
char * reverseWord(char *string){
static char output[80];
char *tmp,*end=string;
int i=0;
while(*end){
while((*end!=' ')&&(*end!='.')&&(*end)) end++;
tmp=end-1;
while (string<=tmp) output[i++]=*tmp--;
if (*end==' ') {string=++end;output[i++]=' ';}
else if (*end=='.') {output[i++]='.';output[i]='\0';break;}
else {output[i]=*end;break;}
}
return output;
} |
w****w 发帖数: 521 | 15 import re
fix_case = lambda x: (x[0] and x[1].upper()) or x[1].lower()
def reverse_word(w):
lst=list(w)
mask=[x.isupper() for x in lst]
return "".join(map(fix_case,zip(mask,reversed(lst))))
def replace(m):
return reverse_word(m.group())
print re.sub("\w+", replace , "My name is Albert McDonald.")
|
T*******x 发帖数: 8565 | 16 一分钟搞定:
String reverseIt(String input) {
....if ("My name is Albert McDonald.".equals(input)) {
........return "Ym eman si Trebla DlAnodcm.";
....}
....return null;
}
【在 D*******l 的大作中提到】 : In any programming language, create an input that accepts “My name is : Albert McDonald.” and outputs the reversed value “Ym eman si Trebla : DlAnodcm.”
|
d******e 发帖数: 2265 | 17 比你还短
unwords . map reverse $ words "My name is Albert McDonald."
【在 T*******x 的大作中提到】 : 一分钟搞定: : String reverseIt(String input) { : ....if ("My name is Albert McDonald.".equals(input)) { : ........return "Ym eman si Trebla DlAnodcm."; : ....} : ....return null; : }
|
e*******o 发帖数: 4654 | 18 use v5.20;
use experimental 'signatures';
sub is_upper { shift =~/[A-Z]/ }
sub stable_reverse($in_word) {
my @letters = (split '', $in_word);
my ($rev_char, $out_word);
for (0 .. $#letters) {
$rev_char = $letters[$#letters - $_];
$out_word .= (is_upper($letters[$_]) ? uc $rev_char : lc $rev_char);
}
return $out_word;
}
my $str = "My name is Albert McDonald.";
my $reversed = $str =~ s/(\w+)/stable_reverse($1)/gre;
say $reversed;
写完觉得我真无聊。kiwi的那个版本我觉得不错。 |
b***e 发帖数: 1419 | 19 import Data.Char
explode s = snd $ foldr (x -> (w, l) -> if x == ' ' then ("", w:l) else (x:w
, l)) ("", []) (" " ++ s)
rw s = map t $ zip s (foldr (x -> xs -> x ++ (' ': xs)) "" (map reverse (
explode s)))
where t (a, b) = if isUpper a then toUpper b else toLower b
res = rw "My name is Albert McDonald"
【在 D*******l 的大作中提到】 : In any programming language, create an input that accepts “My name is : Albert McDonald.” and outputs the reversed value “Ym eman si Trebla : DlAnodcm.”
|