String 将唯一组合映射到数字
我正试图想出一个解决我想到的问题的办法。我有26个字符的排列数,6个可能的点为26^6=308915776。我试图找到一种方法,使我能够将每个数字映射到一个唯一的组合,并能够在一个组合到另一个数字之间来回切换String 将唯一组合映射到数字,string,permutation,String,Permutation,我正试图想出一个解决我想到的问题的办法。我有26个字符的排列数,6个可能的点为26^6=308915776。我试图找到一种方法,使我能够将每个数字映射到一个唯一的组合,并能够在一个组合到另一个数字之间来回切换 An example: 1 = aaaaaa 2 = aaaaab 27 = aaaaba 是否可以编写一个多项式时间算法,在两者之间进行转换和/或是否有任何有效的示例说明我正在尝试执行的操作。您可以通过指针将其映射为双精度: char *example = "abcdef"; dou
An example:
1 = aaaaaa
2 = aaaaab
27 = aaaaba
是否可以编写一个多项式时间算法,在两者之间进行转换和/或是否有任何有效的示例说明我正在尝试执行的操作。您可以通过指针将其映射为双精度:
char *example = "abcdef";
double d = 0;
char *p = (char *)&d;
for (int i=0; i<6; i++)
p[i] = example[i];
// d is your code
char*example=“abcdef”;
双d=0;
char*p=(char*)&d;
对于(int i=0;i,可以通过指针将其映射为双精度:
char *example = "abcdef";
double d = 0;
char *p = (char *)&d;
for (int i=0; i<6; i++)
p[i] = example[i];
// d is your code
char*example=“abcdef”;
双d=0;
char*p=(char*)&d;
对于(inti=0;i这只是我的朋友的基本转换
由于未指定语言,以下是伪代码,数组索引和字符串索引从0开始,赋值为:=
如果将“a”设为0,“z”设为25,则要将基数26转换为基数10:
total:= 0
loop index from 0 to 5
temp:= 'z' - input[index] // Left to right. Single base 26 digit to base 10
total:= 26 * total + temp // Shift left and add the converted digit
increment index and goto loop start
返回字母(基数26)也很容易:
result:= ''
loop index from 0 to 5
temp:= 'a' + input mod 26 // Input modulus 26 is the base 26 digit to add next
result:= temp + result // Append current result to the new base 26 digit
input:= input div 26 // Divide input by 26, throw away the remainder
increment index and goto loop start
如果你希望所有a都是1,那么在从基数26转换到基数10后加一,在从基数10转换到基数26之前减去1。就个人而言,我希望所有a都是0。这只是基数转换,我的朋友
由于未指定语言,以下是伪代码,数组索引和字符串索引从0开始,赋值为:=
如果将“a”设为0,“z”设为25,则要将基数26转换为基数10:
total:= 0
loop index from 0 to 5
temp:= 'z' - input[index] // Left to right. Single base 26 digit to base 10
total:= 26 * total + temp // Shift left and add the converted digit
increment index and goto loop start
返回字母(基数26)也很容易:
result:= ''
loop index from 0 to 5
temp:= 'a' + input mod 26 // Input modulus 26 is the base 26 digit to add next
result:= temp + result // Append current result to the new base 26 digit
input:= input div 26 // Divide input by 26, throw away the remainder
increment index and goto loop start
如果你希望所有a都是1,那么在从基数26转换到基数10后加一,在从基数10转换到基数26之前减去1。我个人认为,所有a都是0