//============================================================================
// Name : 331.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cstdio>
using namespace std;
int a[10], n, ans, T;
int judge(){
for(int i = 0;i < n-1;i++){
if(a[i] > a[i+1]) return 0;
}
return 1;
}
void find(){
if(judge()){
ans++;
return ;
}
for(int i = 0;i < n-1;i++){
if(a[i] > a[i+1]){
swap(a[i], a[i+1]);
find();
swap(a[i], a[i+1]);
}
}
}
int main() {
freopen("a.txt", "r", stdin);
T = 0;
while(scanf("%d", &n)&&n){
T++;
for(int i = 0;i < n;i++){
scanf("%d", &a[i]);
}
ans = 0;
if(!judge()) find();
printf("There are %d swap maps for input data set %d.\n",ans, T);
}
return 0;
}
转载于:https://www.cnblogs.com/ACKOKO/articles/2059368.html