Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 查找随机文本的所有大写字母组合_C_Combinations_Generated - Fatal编程技术网

C 查找随机文本的所有大写字母组合

C 查找随机文本的所有大写字母组合,c,combinations,generated,C,Combinations,Generated,在C语言中,我有一个带有随机数和不带大写字母的字符数组。我需要弄清楚如何生成所有可能的组合,包括大写字母,同时保持数字不变,但我甚至不知道从哪里开始。(例如abc123、abc123、abc123、abc123、abc123、abc123、abc123、abc123、abc123)暂时不考虑数字 假设您现在有x个字符。如果x=3(假设),则考虑从0到7的数字,因为2 ^ 3 -1是7(-1,因为必须考虑0作为一个状态)。p> 然后你必须遍历所有的数字,并在一个字母的位为1时将其大写 例如: a

在C语言中,我有一个带有随机数和不带大写字母的字符数组。我需要弄清楚如何生成所有可能的组合,包括大写字母,同时保持数字不变,但我甚至不知道从哪里开始。(例如abc123、abc123、abc123、abc123、abc123、abc123、abc123、abc123、abc123)

暂时不考虑数字

假设您现在有x个字符。如果x=3(假设),则考虑从0到7的数字,因为2 ^ 3 -1是7(-1,因为必须考虑0作为一个状态)。p> 然后你必须遍历所有的数字,并在一个字母的位为1时将其大写

例如:

  • abc-000(0)
  • abC-001(1)
  • aBc-010(2)
  • aBC-011(3)
  • Abc-100(4)
这是它的代码,给那些无法理解理论解释的人

void enumerate (String input) {

    int count = 0;
    //count the number of non-digit characters
    for(int i=0; i<input.length(); i++)
        if(!Character.isDigit(input.charAt(i))) {
            count++;
        }

   count =(int) Math.pow(2,count); 
   //printing all the combinations.
   int i=0, digit=0;
   while(count--> 0) {
       String output = ""; 
       for(int j=input.length()-1; j>=0; j--) {
           char c = input.charAt(j);   
           if(Character.isDigit(c))
               output = (char)c + output;
           else {
               output = (char) (((i&1) == 1)? c-32 : c) + output;
               i = i>>1;
           }
       }
       System.out.println(output);
       i = ++digit;

   }
}
void枚举(字符串输入){
整数计数=0;
//计算非数字字符的数量
对于(int i=0;i 0){
字符串输出=”;
对于(int j=input.length()-1;j>=0;j--){
字符c=输入字符(j);
if(字符isDigit(c))
输出=(字符)c+输出;
否则{
输出=(char)((i&1)==1)?c-32:c)+输出;
i=i>>1;
}
}
系统输出打印项次(输出);
i=+位;
}
}

暂时不考虑数字

假设您现在有x个字符。如果x=3(假设),则考虑从0到7的数字,因为2 ^ 3 -1是7(-1,因为必须考虑0作为一个状态)。p> 然后你必须遍历所有的数字,并在一个字母的位为1时将其大写

例如:

  • abc-000(0)
  • abC-001(1)
  • aBc-010(2)
  • aBC-011(3)
  • Abc-100(4)
这是它的代码,给那些无法理解理论解释的人

void enumerate (String input) {

    int count = 0;
    //count the number of non-digit characters
    for(int i=0; i<input.length(); i++)
        if(!Character.isDigit(input.charAt(i))) {
            count++;
        }

   count =(int) Math.pow(2,count); 
   //printing all the combinations.
   int i=0, digit=0;
   while(count--> 0) {
       String output = ""; 
       for(int j=input.length()-1; j>=0; j--) {
           char c = input.charAt(j);   
           if(Character.isDigit(c))
               output = (char)c + output;
           else {
               output = (char) (((i&1) == 1)? c-32 : c) + output;
               i = i>>1;
           }
       }
       System.out.println(output);
       i = ++digit;

   }
}
void枚举(字符串输入){
整数计数=0;
//计算非数字字符的数量
对于(int i=0;i 0){
字符串输出=”;
对于(int j=input.length()-1;j>=0;j--){
字符c=输入字符(j);
if(字符isDigit(c))
输出=(字符)c+输出;
否则{
输出=(char)((i&1)==1)?c-32:c)+输出;
i=i>>1;
}
}
系统输出打印项次(输出);
i=+位;
}
}

暂时不考虑数字

假设您现在有x个字符。如果x=3(假设),则考虑从0到7的数字,因为2 ^ 3 -1是7(-1,因为必须考虑0作为一个状态)。p> 然后你必须遍历所有的数字,并在一个字母的位为1时将其大写

例如:

  • abc-000(0)
  • abC-001(1)
  • aBc-010(2)
  • aBC-011(3)
  • Abc-100(4)
这是它的代码,给那些无法理解理论解释的人

void enumerate (String input) {

    int count = 0;
    //count the number of non-digit characters
    for(int i=0; i<input.length(); i++)
        if(!Character.isDigit(input.charAt(i))) {
            count++;
        }

   count =(int) Math.pow(2,count); 
   //printing all the combinations.
   int i=0, digit=0;
   while(count--> 0) {
       String output = ""; 
       for(int j=input.length()-1; j>=0; j--) {
           char c = input.charAt(j);   
           if(Character.isDigit(c))
               output = (char)c + output;
           else {
               output = (char) (((i&1) == 1)? c-32 : c) + output;
               i = i>>1;
           }
       }
       System.out.println(output);
       i = ++digit;

   }
}
void枚举(字符串输入){
整数计数=0;
//计算非数字字符的数量
对于(int i=0;i 0){
字符串输出=”;
对于(int j=input.length()-1;j>=0;j--){
字符c=输入字符(j);
if(字符isDigit(c))
输出=(字符)c+输出;
否则{
输出=(char)((i&1)==1)?c-32:c)+输出;
i=i>>1;
}
}
系统输出打印项次(输出);
i=+位;
}
}

暂时不考虑数字

假设您现在有x个字符。如果x=3(假设),则考虑从0到7的数字,因为2 ^ 3 -1是7(-1,因为必须考虑0作为一个状态)。p> 然后你必须遍历所有的数字,并在一个字母的位为1时将其大写

例如:

  • abc-000(0)
  • abC-001(1)
  • aBc-010(2)
  • aBC-011(3)
  • Abc-100(4)
这是它的代码,给那些无法理解理论解释的人

void enumerate (String input) {

    int count = 0;
    //count the number of non-digit characters
    for(int i=0; i<input.length(); i++)
        if(!Character.isDigit(input.charAt(i))) {
            count++;
        }

   count =(int) Math.pow(2,count); 
   //printing all the combinations.
   int i=0, digit=0;
   while(count--> 0) {
       String output = ""; 
       for(int j=input.length()-1; j>=0; j--) {
           char c = input.charAt(j);   
           if(Character.isDigit(c))
               output = (char)c + output;
           else {
               output = (char) (((i&1) == 1)? c-32 : c) + output;
               i = i>>1;
           }
       }
       System.out.println(output);
       i = ++digit;

   }
}
void枚举(字符串输入){
整数计数=0;
//计算非数字字符的数量
对于(int i=0;i 0){
字符串输出=”;
对于(int j=input.length()-1;j>=0;j--){
字符c=输入字符(j);
if(字符isDigit(c))
输出=(字符)c+输出;
否则{
输出=(char)((i&1)==1)?c-32:c)+输出;
i=i>>1;
}
}
系统输出打印项次(输出);
i=+位;
}
}

事实上,这将是2^n种可能性,n表示字符数组中字母字符的数量

为了解决你的问题,我建议你考虑一下,我想这是实现你想做的事情的最简单的方法,你只需要想得和平常有点不同

编辑:下面是一些实现

void enumerate(char *str, int n)
{
  printf("%s\n", str); // Print one solution
  while (++n < strlen(str)) // Loop while you don't reach the end
    if (str[n] > 96 && str[n] < 123) // Check if str[n] is alphabetic
      {
        char *tmp = calloc(strlen(str) + 1, sizeof(char));
        strcpy(tmp, str); // Create a copy of the initial string
        tmp[n] -= 32; // Put tmp[n] = str[n] in uppercase
        enumerate(tmp, n); // Call recursion with new string and current position
      }
}
导致

abc123
Abc123
ABc123
ABC123
AbC123
aBc123
aBC123
abC123

实际上,它将是2^n个可能性,n表示字符数组中的字母字符数量

为了解决你的问题,我建议你考虑一下,我想这是实现你想做的事情的最简单的方法,你只需要想得和平常有点不同

编辑:下面是一些实现

void enumerate(char *str, int n)
{
  printf("%s\n", str); // Print one solution
  while (++n < strlen(str)) // Loop while you don't reach the end
    if (str[n] > 96 && str[n] < 123) // Check if str[n] is alphabetic
      {
        char *tmp = calloc(strlen(str) + 1, sizeof(char));
        strcpy(tmp, str); // Create a copy of the initial string
        tmp[n] -= 32; // Put tmp[n] = str[n] in uppercase
        enumerate(tmp, n); // Call recursion with new string and current position
      }
}
导致

abc123
Abc123
ABc123
ABC123
AbC123
aBc123
aBC123
abC123

实际上,它将是2^n个可能性,n表示字符数组中的字母字符数量

为了解决你的问题,我建议你考虑一下,我想这是实现你想做的事情的最简单的方法,你只需要想得和平常有点不同

编辑:下面是一些实现

void enumerate(char *str, int n)
{
  printf("%s\n", str); // Print one solution
  while (++n < strlen(str)) // Loop while you don't reach the end
    if (str[n] > 96 && str[n] < 123) // Check if str[n] is alphabetic
      {
        char *tmp = calloc(strlen(str) + 1, sizeof(char));
        strcpy(tmp, str); // Create a copy of the initial string
        tmp[n] -= 32; // Put tmp[n] = str[n] in uppercase
        enumerate(tmp, n); // Call recursion with new string and current position
      }
}
导致

abc123
Abc123
ABc123
ABC123
AbC123
aBc123
aBC123
abC123

实际上,它将是2^n个可能性,n表示字符数组中的字母字符数量

为了解决你的问题,我建议你考虑一下,我想这是实现你想做的事情的最简单的方法