zoukankan      html  css  js  c++  java
  • 1256 Anagram

    题目链接: http://poj.org/problem?id=1256

    题意: 根据自定义的字典序: 'A'<'a'<'B'<'b'<...<'Z'<'z' 和输入的字符串(最长为13), 输出按新字典序的全排列.

    分析: 题目简单, 但是要处理好映射关系.

    #include <iostream>
    #include <string>
    #include <algorithm>
    using namespace std;
    
    int mp[13]; // 字符串中的各个字符按相对大小映射到mp中.
    
    int main(){
        int T,n;
        cin>>T;
        while(T--){
            string s;
            cin>>s;
            int len = s.length();
            for(int i=0;i<len;++i){
                if(s[i]>='a' && s[i] <= 'z'){
                    mp[i] = (s[i]-'a')*2+1;
                }else{
                    mp[i] = (s[i]-'A')*2;
                }
            }
            sort(mp,mp+len);
            do{
                for(int i=0;i<len;++i){
                    char c;
                    if(mp[i]%2){
                        c = 'a'+mp[i]/2;
                    }else{
                        c = 'A'+mp[i]/2;
                    }
                    cout<<c;
                }
                cout<<endl;
            }while(next_permutation(mp,mp+len));
        }
        return 0;
    }
    
  • 相关阅读:
    单例模式
    二、CSS
    十一、多线程
    十二、协程
    十、多进程
    九、内存管理
    八、元类
    七、上下文管理器/魔术方法
    六、单例模式
    五、装饰器
  • 原文地址:https://www.cnblogs.com/roger9567/p/4887316.html
Copyright © 2011-2022 走看看