# C语言基础

## 0001 求26个字母的全排列

That's a tough question but thankfully, our team is on it. Please bear with us while we're investigating.

```cpp
#include <stdio.h>
#include <iostream>
using namespace std;
#define N 10
include
#include <stdio.h>
using namespace std;
 
int n;
char a[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w',
'x','y','z'};
int ​count=0;
 
void swap(int x,int y)
{
	int tmp;
	tmp = a[x];
	a[x] = a[y];
	a[y] = tmp;
}
 
void search(int k)
{
	int i;
	
	if(k == n)
	{	
		for(i = 0;i < n;i++)
		{
			cout << a[i];
			
		}
		++count;

		cout << endl;
	}
	else
	{
		for(i = k;i < n;i++)
		{
			swap(i,k);
			search(k+1);
			swap(i,k);
		}
		
	}
		
	
}
 
int main()
{
	cin >> n;
	search(0);
	printf("共%d种",count); 

	return 0;
}
```

此题的思路很简单。对于一个不含重复元素的全排列，使用递归划分，第一次{a}search（0，0）自己与自己排列看成已排列好，第二次{a,b},search(c),以此类推，直到只剩一个，表示已经排好，然后从头开始排列{a,c},search(b)……

## Have you had a chance to answer the previous question?

Yes, after a few months we finally found the answer. Sadly, Mike is on vacations right now so I'm afraid we are not able to provide the answer at this point.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://it-amateurs.gitbook.io/it-amateurs/c-yu-yan-ji-chu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
