zoukankan      html  css  js  c++  java
  • leetcode-剑指38-?

    // language C with STL(C++)
    // 剑指38
    // https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/
    
    
    class Solution {
    public:
    	vector<string> res;
    	char zimu[8];
    	int num[8];
    	int total=8;
    	int LEN;
    	int asize=0;
    	string a;
    	void beifen(char a[], int b[], int shu){
    		for(int i = 0; i<shu; i++){
    			a[i] = zimu[i];
    			b[i] = num[i];
    		}
    	}
    
    
    	void huigui(char a[], int b[], int shu){
    		for(int i = 0; i<shu; i++){
    			zimu[i] = a[i];
    			num[i]  = b[i];
    		}
    	}
    
    	void display(){
    		for(int i =0; i<total; i++){
    			printf("%c-", zimu[i]);
    		}
    		printf("
    ");
    		for(int i =0; i<total; i++){
    			printf("%d-", num[i]);
    		}
    	}
    
    
    	void zuo(int done){
    		if(done == LEN){
    			string b;
                for(int j = 0; j< LEN; j++){
                    // printf("%c",a[j]);
                    b.push_back(a[j]);
                }
                // printf("
    ");
                // printf("%d",b.size());
    			res.push_back(b);
                // printf("%d",res.size());
    			return;
    		}
    		char lin[total];
    		int shi[total];
    		beifen(lin,shi,total);	// 是否用掉
    		for(int i =0; i<total; i++){
    			if(num[i]>0){
    				num[i]--;
    				a.push_back(zimu[i]);
    				zuo(done+1);
    				huigui(lin,shi,total);
    				a.pop_back();
    			}
    		}
    	}
    
    
    
        vector<string> permutation(string s) {
        	LEN =s.length();
        	if(LEN ==0)
        		return res;
        	int next = 0;
        	bool flag = true;
        	for(int i = 0; i< LEN; i++){
        		flag = true;
        		for(int j = 0; j<next; j++){
        			if(zimu[j] == s[i]){
        				num[j]++;
        				flag = false;
        				break;
        			}
        		}
        		if(flag){
    				zimu[next] = s[i];
    				num[next] = 1;
    				next++;
        		}
        	}
        	
            // printf("%d-", LEN);
            // printf("%d", next);
        	total = next;// 统计完毕,total 就是不同的字母的数量
        	// printf("%d-", total);
        	// display();
        	zuo(0);
        	return res;
        }
    };
    
  • 相关阅读:
    什么是CMS
    TP3.2项目—微信推广页
    《实用技巧》——让你的网站变成响应式的3个简单步骤
    thinkphp分页带数据
    tp框架表单验证 及ajax
    tp框架做留言板
    随时修改添加,thinkphp小知识
    thinkphp使用ajax
    thinkphp修改和删除数据
    tp框架查询
  • 原文地址:https://www.cnblogs.com/gallien/p/14391778.html
Copyright © 2011-2022 走看看