zoukankan      html  css  js  c++  java
  • uva-10098

       所有的排列,但是要不重复

    #include<stdio.h>
    #include<iostream>
    #include<sstream>
    #include<queue>
    #include<map>
    #include<memory.h>
    #include <math.h>
    #include<time.h>
    #include <stdlib.h>
    #include <algorithm>
    using namespace std;
    #define N 12
    int vis[N];
    char a[N];
    char b[N];
    int length;
    int n;
    int final = 0;
    void dfs(int cur)
    {
    	if(cur == length)
    	{
    		for(int i = 0; i < cur; i++)
    			cout << b[i];
    		cout << endl;
    		return;
    	}
    	for(int i = 0; i < length; i++)
    	{
    		if(!i || a[i] != a[i - 1])
    		{
    			int c1 = 0, c2 = 0;
    			for(int j = 0; j < cur; j++)
    				if(b[j] == a[i])
    					c1++;
    
    			for(int j = 0; j < length; j++)
    				if(a[j] == a[i])
    					c2++;
    			if(c1 < c2)
    			{
    				b[cur] = a[i];
    				dfs(cur + 1);
    			}
    		}
    
    	}
    }
    void sort()
    {
    	for(int i = 0; i < length; i++)
    	{
    		for(int j = 1; j < length - i; j++)
    		{
    			if(a[j] < a[j - 1])
    			{
    				char cc = a[j];
    				a[j] = a[j - 1];
    				a[j - 1] = cc;
    			}
    		}
    	}
    
    }
    int main(const int argc, char** argv)
    {
    	freopen("d:\1.txt", "r", stdin);
    	cin >> n;
    	while (n--)
    	{
    		memset(a, 0, sizeof(a));
    		scanf("%s", a);
    		length = strlen(a);
    		sort();
    		dfs(0);
    		//if(n != 0)
    			cout << endl;
    	}
    	return 0;
    }
    

      

    #include<stdio.h>
    #include<iostream>
    #include<sstream>
    #include<queue>
    #include<map>
    #include<memory.h>
    #include <math.h>
    #include<time.h>
    #include <stdlib.h>
    #include <algorithm>
    using namespace std;
    #define N 12
    int vis[N];
    char a[N];
    char b[N];
    int length;
    int n;
    int final = 0;
    void dfs(int cur)
    {
    	if(cur == length)
    	{
    		for(int i = 0; i < cur; i++)
    			cout << b[i];
    		cout << endl;
    		return;
    	}
    	for(int i = 0; i < length; i++)
    	{
    		if(!i || a[i] != a[i - 1])
    		{
    			int c1 = 0, c2 = 0;
    			for(int j = 0; j < cur; j++)
    				if(b[j] == a[i])
    					c1++;
    
    			for(int j = 0; j < length; j++)
    				if(a[j] == a[i])
    					c2++;
    			if(c1 < c2)
    			{
    				b[cur] = a[i];
    				dfs(cur + 1);
    			}
    		}
    
    	}
    }
    void sort()
    {
    	for(int i = 0; i < length; i++)
    	{
    		for(int j = 1; j < length - i; j++)
    		{
    			if(a[j] < a[j - 1])
    			{
    				char cc = a[j];
    				a[j] = a[j - 1];
    				a[j - 1] = cc;
    			}
    		}
    	}
    
    }
    int main(const int argc, char** argv)
    {
    	freopen("d:\1.txt", "r", stdin);
    	cin >> n;
    	while (n--)
    	{
    		memset(a, 0, sizeof(a));
    		scanf("%s", a);
    		length = strlen(a);
    		sort();
    		do
    		{
    			cout << a << endl;
    		} while (next_permutation(a, a + length));
    		cout << endl;
    	}
    	return 0;
    }
    

      想看库函数源码了。。。。。

  • 相关阅读:
    基于Windows Mobile 5.0的GPS应用程序开发
    iis6应用程序池被自动禁用问题 应用程序池'DefaultAppPool' 被自动禁用
    Axapta物流模块深度历险(八)
    AX的报表服务器(一)
    AX的企业门户(一)
    SQL Server2005 Reporting Services 管理站点
    SQL Server2005 Reporting Services的卸载
    耐心的解决问题
    危险操作符
    慢慢的坚持啊
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/7828839.html
Copyright © 2011-2022 走看看