zoukankan      html  css  js  c++  java
  • 1146 ID Codes

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

    题意: 给定一个字符串(长度不超过50), 求这个字符串的下一个字典序的字符串, 如果已经是最大字典序, 那么输出 "No successor".

    分析: <algorithm>中有一个现成的next_permutation(begin, end), 对输入的字符串进行排列.

    原型如下:

    template<class BidirectionalIterator>  
    bool next_permutation(  
          BidirectionalIterator _First,   
          BidirectionalIterator _Last  
    );  
    template<class BidirectionalIterator, class BinaryPredicate>  
    bool next_permutation(  
          BidirectionalIterator _First,   
          BidirectionalIterator _Last,  
          BinaryPredicate _Comp  
     );
    

    AC代码:

    #include <iostream>
    #include <algorithm>
    #include <string>
    using namespace std;
    string line;
    
    bool comp(char a, char b){
        return a>b;
    }
    
    int main(){
        while(cin>>line){
            if(line.at(0) == '#')
                break;
            string s(line);
            sort(s.begin(),s.end(),comp);
            if(line == s){
                cout<<"No Successor"<<endl;
                continue;
            }
            next_permutation(line.begin(),line.end());
            cout<<line<<endl;
        }
        return 0;
    }
    
  • 相关阅读:
    ultraedit 窗口布局
    Oracle之Char VarChar VarChar2
    Python之pickle
    Python之xpath
    Python常用数据结构之heapq模块
    Python实现排序算法之快速排序
    Python常用数据结构之collections模块
    New York is 3 hours ahead of California
    leetcode978
    leetcode979
  • 原文地址:https://www.cnblogs.com/roger9567/p/4887215.html
Copyright © 2011-2022 走看看