zoukankan      html  css  js  c++  java
  • POJ 1146 ID Codes (UVA146)

    // 求下一个排列
    // 如果已经是最后一个排列
    // 就输出 No Successor
    // stl 或 自己写个 生成排列 我测试了下 两个速率是一样的、只是代码长度不同

    /*
    #include <iostream>
    #include <string>
    #include<sstream>
    #include <cmath>
    #include <map>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    char s[100];
    int n;
    int main()
    {
    
       while(scanf("%s",s),strcmp(s,"#"))
       {
           n=strlen(s);
           if(next_permutation(s,s+n))
             printf("%s
    ",s);
           else
             printf("No Successor
    ");
       }
       return 0;
    }
    
    */
    
    #include <iostream>
    #include <string>
    #include<sstream>
    #include <cmath>
    #include <map>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    char s[100];
    int n;
    void change(int l,int r)
    {
         while(l<r)
         {
             swap(s[l],s[r]);
             l++;
             r--;
         }
    }
     bool permutation()
     {
         int i=n-1;
         while(i>0&&s[i-1]>=s[i]) i--;
         if(!i) return false;
         int k=i,j=n-1;
         for(;j>i;j--)
          if(s[j]>s[i-1]){
              k=j;
              break;
         }
         swap(s[i-1],s[k]);
         change(i,n-1);
         return true;
     }
    int main()
    {
    
       while(scanf("%s",s),strcmp(s,"#"))
       {
           n=strlen(s);
           if(permutation())
             printf("%s
    ",s);
           else
             printf("No Successor
    ");
       }
       return 0;
    }
  • 相关阅读:
    Vue.js监听事件
    Vue.js组件传值
    Vue.js安装
    C#中输入法全角转换半角
    文件夹操作
    转JSON字符串,并进行AES加密
    ReportView报表的使用
    c++读入优化
    快读板子
    【转】2020年 大二上 ACM
  • 原文地址:https://www.cnblogs.com/372465774y/p/3603082.html
Copyright © 2011-2022 走看看