Redian新闻
>
背光的EINK 哪个好点??
avatar
s*n
2
string permutation,怎么处理重复字母?
avatar
r*y
3
amazon的好 还是nook GW 的好??
NOOK的有打折 貌似70多拿下了
avatar
l*a
4
1) sort
2) get permutation

【在 s*******n 的大作中提到】
: string permutation,怎么处理重复字母?
avatar
n*y
5
都差不多。我喜欢nook glowlight,我认识的所有别人都喜欢kindle, paperwhite.
avatar
w*s
6
Two implementation. one use sort and one use hash.
//pre: str is sorted.
void PermutationWithDuplicate(char *str, int position)
{
if (position == strlen(str)) {
printf("%s", str);
return;
}

char lastChar = '\0';
for (int i = position; i{
//skip those character which is duplicated. Since the string is
sorted, it's easy.
if (lastChar == str[i] ) continue;

lastChar = str[i];
swap(str[position], str[i]);
PermutationWithDuplicate(str,position+1);
swap(str[i] , str[position]);
}
}
//pre: str is not sorted and str can't be changed. We can use hash to do
this.
void PermutationWithDuplicateHash(char *str, int position)
{
int HashTable[128] = {0}; //assume ASCII
if (position == strlen(str)) {
printf("%s", str);
return;
}

for (int i = position; i{
if (HashTable[str[i]) > 0) continue;
else{
HashTable[str[i]] = 1;
}

swap(str[position], str[i]);
PermutationWithDuplicateHash(str,position+1);
swap(str[i] , str[position]);
}
}
main()
{
char str[] = "hello world";
// If duplicated character is allowed, let's sort the string first.
sort(str);
PermutationWithDuplicate(str, 0)

//method 2. Using Hashtable to make a judgement whether it's duplicated
PermutationWithDuplicateHash(str, 0)
}
avatar
r*y
7

我也一直是kindle用户 不过paper是不是有点硬件问题? 我没follow

【在 n****y 的大作中提到】
: 都差不多。我喜欢nook glowlight,我认识的所有别人都喜欢kindle, paperwhite.
avatar
m*i
8
It is still a solution without sorting or hashing.
public void permutationRecursive(int[] arr, int index) {
if (arr.length == index) {
for (int i = 0; i < arr.length; ++i) {
System.out.printf("%d", arr[i]);
}
System.out.println();
return;
}
int lastSwap = 0;
for (int i = index; i < arr.length; ++i) {
if (arr[i] == arr[index] && i != index) continue;
if (arr[i] == lastSwap) continue;
lastSwap = arr[i];
swap(arr, i, index);
permutationRecursive(arr, index+1);
swap(arr, i, index);

}
}

private void swap(int[] arr, int i, int j) {
assert (i >= 0 && i >= 0 && i < arr.length && j < arr.length);
if (i != j) {
arr[i] = arr[i] ^ arr[j];
arr[j] = arr[i] ^ arr[j];
arr[i] = arr[i] ^ arr[j];
}
}


/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr = {2,3,2,3};
Permutation p = new Permutation();
System.out.println("Permutation");
p.permutationRecursive(arr, 0);
}
avatar
a*m
9
俺脚着kindle pw比nook gw好不少。

【在 r******y 的大作中提到】
: amazon的好 还是nook GW 的好??
: NOOK的有打折 貌似70多拿下了

avatar
s*n
10
nice..thanks..
avatar
n*y
11
不知道。我有个朋友入了一个,非常喜欢。

【在 r******y 的大作中提到】
:
: 我也一直是kindle用户 不过paper是不是有点硬件问题? 我没follow

avatar
H*s
12
这样不行啊, 如果输入: 1323, 输出有重复的。
我明白你的思路:就是每层循环在一个位置,每个unique字符只出现一次,
但是这只有hash才能保证啊。否则,例子中第二个3的lastSwap是2啊,所以还是有重复
的。

【在 m****i 的大作中提到】
: It is still a solution without sorting or hashing.
: public void permutationRecursive(int[] arr, int index) {
: if (arr.length == index) {
: for (int i = 0; i < arr.length; ++i) {
: System.out.printf("%d", arr[i]);
: }
: System.out.println();
: return;
: }
: int lastSwap = 0;

avatar
S*r
13
kindle paperwhite不是背光

【在 r******y 的大作中提到】
: amazon的好 还是nook GW 的好??
: NOOK的有打折 貌似70多拿下了

avatar
w*x
14
每个递归栈上用bool chr[256]
avatar
t*y
15
Nook 背光有70刀了?哪儿啊

【在 r******y 的大作中提到】
: amazon的好 还是nook GW 的好??
: NOOK的有打折 貌似70多拿下了

avatar
t*r
16

neat

【在 w*******s 的大作中提到】
: Two implementation. one use sort and one use hash.
: //pre: str is sorted.
: void PermutationWithDuplicate(char *str, int position)
: {
: if (position == strlen(str)) {
: printf("%s", str);
: return;
: }
:
: char lastChar = '\0';

avatar
f*g
17
local staples

【在 t*******y 的大作中提到】
: Nook 背光有70刀了?哪儿啊
avatar
w*o
18
测试了一下,用hash的方法PermutationWithDuplicateHash是对的。
另一个先sort,然后只用一个变量lastChar的方法,不正确,会有重复的输出。

【在 w*******s 的大作中提到】
: Two implementation. one use sort and one use hash.
: //pre: str is sorted.
: void PermutationWithDuplicate(char *str, int position)
: {
: if (position == strlen(str)) {
: printf("%s", str);
: return;
: }
:
: char lastChar = '\0';

avatar
r*y
19

现在已经每了

【在 t*******y 的大作中提到】
: Nook 背光有70刀了?哪儿啊
avatar
h*e
20
kindle pw的优点是屏幕分辨率高,1024*768
nook是800 *600
nook的优点是用android 2.1系统,可以越狱后装在线阅读软件
而kindle只能多看
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。