根据字符表穷举密码

今天遇到一个题,要求根据 a-z0-9 这些字符穷举出所有的可能的密码,搞了搞,代码如下

#include <stdio.h>
#include <string.h>

#define PWD_LEN (3)

char table[] = "abcdefghijklmnopqrstuvwxyz0123456789";
int table_len = strlen(table);

void f(char pwd[], int curr) {
	if (curr == PWD_LEN) {
		printf("%sn", pwd);
	} else {
		for (int i=0; i<table_len; i++)	{
			pwd[curr] = table[i];
			f(pwd, curr+1);
		}
	}
}

int main() {
	char pwd[PWD_LEN+1];
	pwd[PWD_LEN] = '\0';
	f(pwd, 0);
	return 0;
}

输出就不贴了,太长了

Leave a Reply

Your email address will not be published. Required fields are marked *