zoukankan      html  css  js  c++  java
  • poj 1256 Anagram

    按要求排序,然后调用next_permutation即可。

    #include<iostream>
    #include<algorithm>
    #include<cstring>
    
    using namespace std;
    
    
    bool cmp(const char &a, const char &b)
    {
    	if(a <= 'Z' && a >= 'A' && b <= 'Z' && b >= 'A')
    		return a < b;
    	if(a <= 'z' && a >= 'a' && b <= 'z' && b >= 'a')
    		return a < b;
    	if(a <= 'Z' && a >= 'A' && b <= 'z' && b >= 'a')
    		return a + 32 <= b;
    	if(a<='z' && a >='a' && b <= 'Z' && b >= 'A')
    		return a < (b + 32);
    }
    
    int main()
    {
    	int num = 0;
    	cin >> num;
    	while(num--)
    	{
    		char str[100];
    		cin >> str;
    		int length = strlen(str);
    		sort(str, str+length, cmp);
    		cout << str << endl;
    		while(next_permutation(str, str + length, cmp))
    		{
    			cout << str << endl;
    		}
    	}
    	return 0;
    }
    


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    gdb --configuration
    firecracker 编译
    gvisor 编译
    gvisor
    rust Deref
    rust explicit
    rust move
    rust drop
    出租人对经营租赁的会计处理
    关于以公允价值计量的投资性房地产的处置
  • 原文地址:https://www.cnblogs.com/wanglaoda/p/4937123.html
Copyright © 2011-2022 走看看