H***e 发帖数: 476 | 1 string = '"abc",
打印所有长度为6的字符可以重复的string permutation(但是输出不能重复)
也就是打印
aaaaaa
aaaaab
aaaaac
aaabac
....
我觉得很费解。 |
c**********e 发帖数: 2007 | 2 This looks nasty, but it should work.
char* s=string.c_str();
for(int i1=0;i1<3;i1++) {
for(int i2=0;i2<3;i2++) {
for(int i3=0;i3<3;i3++) {
for(int i4=0;i4<3;i4++) {
for(int i5=0;i5<3;i5++) {
for(int i6=0;i6<3;i6++) {
cout << s[i1] << s[i2] << s[i3] << s[i4] << s[i5] << s[i6] << endl;
}
}
}
}
}
} |
H***e 发帖数: 476 | 3 i guess it is asking for a systematic method...
【在 c**********e 的大作中提到】 : This looks nasty, but it should work. : char* s=string.c_str(); : for(int i1=0;i1<3;i1++) { : for(int i2=0;i2<3;i2++) { : for(int i3=0;i3<3;i3++) { : for(int i4=0;i4<3;i4++) { : for(int i5=0;i5<3;i5++) { : for(int i6=0;i6<3;i6++) { : cout << s[i1] << s[i2] << s[i3] << s[i4] << s[i5] << s[i6] << endl; : }
|
c**********e 发帖数: 2007 | 4 First, create a c-str which has no replicates. The length is N. If we want
to get new strings with length M, it is a simple replication. It can be done
recursively for M. The total number of rows is N^M.
【在 H***e 的大作中提到】 : i guess it is asking for a systematic method...
|
s******n 发帖数: 226 | 5 Don't need so many for loops. Only 2 while loop will work.
Go to see 编程之美 |
H***e 发帖数: 476 | 6 谢谢
全称叫什么名字呢
【在 s******n 的大作中提到】 : Don't need so many for loops. Only 2 while loop will work. : Go to see 编程之美
|
c**********e 发帖数: 2007 | 7 Use two loops:
for(int i=0;i<729;i++) {
for(int j=0;j<6;j++) {
m = k % 3; k = k/3;
cout << s[m];
}
cout << end;
}
【在 s******n 的大作中提到】 : Don't need so many for loops. Only 2 while loop will work. : Go to see 编程之美
|
c**********e 发帖数: 2007 | 8 Use one loop: (Hehe, nasty again)
for(int i=0;i<3^6;i++) {
i1 = i/243;
i2 = (i/81) % 3;
i3 = (i/27) % 3;
i4 = (i/9) % 3;
i5 = (i/3) % 3;
i6 = i % 3;
cout << s[i1] << s[i2] << s[i3] << s[i4] << s[i5] << s[i6] << endl;
} |
c**********e 发帖数: 2007 | 9 This one can be generalized: To permut s[N], use two loops
for(int i=0;i
for(int j=0;j
m = k % N; k = k/N;
cout << s[m];
}
cout << end;
} |
s******n 发帖数: 226 | 10 OK. I did not test your solution, but the solution offerred by MSRA still
seems clearer than yours.
【在 c**********e 的大作中提到】 : This one can be generalized: To permut s[N], use two loops : for(int i=0;i: for(int j=0;j: m = k % N; k = k/N; : cout << s[m]; : } : cout << end; : }
|
c**********e 发帖数: 2007 | 11 Why not post the MSRA solution here?
【在 s******n 的大作中提到】 : OK. I did not test your solution, but the solution offerred by MSRA still : seems clearer than yours.
|
s******n 发帖数: 226 | 12 I am packing for moving, so I cannot find it. Just try from my rememberance
idea: same as phone pad interprete to word:
char phonePad[m][n]; // phone pad
int answer[t]; // index of char in the answers corresponding yo each
digits
int num[t]; // phone number to interprete
int k = t-1;
while(true){
print; // using phonePad
while(k>=0){
if( answer[k]
answer[k]++;
break;
}
answer[k] = 0;
k--;
}
if(k<0) break;
}
【在 c**********e 的大作中提到】 : Why not post the MSRA solution here?
|
q****x 发帖数: 7404 | 13 就是abc三个字符可重复,输出所有组合。每个位置都有三个选择,相当于六位的三进
制数穷举。
【在 H***e 的大作中提到】 : string = '"abc", : 打印所有长度为6的字符可以重复的string permutation(但是输出不能重复) : 也就是打印 : aaaaaa : aaaaab : aaaaac : aaabac : .... : 我觉得很费解。
|