Re: [问题] 请问如何写出奇偶分离合并程式

楼主: bleed1979 (十三)   2014-10-01 08:31:32
※ 引述《NoMoneys (没有钱)》之铭言:
: 小弟涉入程式尚浅
: 想了许久还是解不出来
: ex:135246→123456
: acebd→abcde
: wrdol→world
: 像是这样输出结果
: 希望高手帮忙解答感谢
: 不好意思 我想请问的是程式码该如何撰写才能达到这样的答案
: 左边是输入右边是输出
写大概的码给你,因为解题观念不限语言。
所以如果看了还是无法完成,那你需要加强语法。
回传的字符阵列就是与输入字串等长的输出。
char[] method(input s) {
char[] output = new char[s.length()];
int x = s.length() is odd ? 1 : 0;
int y = s.length() / 2;
int j = 0;
loop i from 0 to y - 1 step 1 {
output[j] = s[i];
output[j + 1] = s[x + y + i];
j += 2;
}
if(s.length() is odd) {
output[s.length() - 1] = s[y];
}
return output;
}

Links booklink

Contact Us: admin [ a t ] ucptt.com