用c语言输出前N个大写字母的有重复全排列,包括重复的也输出
时间: 2023-05-31 18:06:46 浏览: 84
#include <stdio.h>
#include <string.h>
void permutation(char str[], int len, int n) {
static int count = 0;
static int used[26] = {0};
static char result[100] = {0};
if (count == n) {
printf("%s\n", result);
return;
}
for (int i = 0; i < len; i++) {
if (used[i]) {
continue;
}
result[count] = str[i];
used[i] = 1;
count++;
permutation(str, len, n);
count--;
used[i] = 0;
}
}
int main() {
int n;
printf("Enter n: ");
scanf("%d", &n);
char str[26];
for (int i = 0; i < 26; i++) {
str[i] = 'A' + i;
}
int len = strlen(str);
permutation(str, len, n);
return 0;
}
阅读全文