POJ 1146 ID Codes (STL)

ID Codes
 

STL知识点:

给你一个字符串,求用这个字符串重新组合后,比这个字符串大的下一个字符串。

例:

 

abaacb   ->   ababac
cba -> abc
C++:
  next_permutation(a, a+len); 当然,prev_permutation就是求前一种排列组合的了。
POJ 1146 Code:

 

 1 #include <map>
 2 #include <stack>
 3 #include <queue>
 4 #include <math.h>
 5 #include <stdio.h>
 6 #include <string.h>
 7 #include <iostream>
 8 #include <limits.h>
 9 #include <algorithm>
10 #define LL long long
11 #define min(a,b) (a>b?b:a)
12 #define max(a,b) (a>b?a:b)
13 #define eps 1e-9
14 #define INF 1 << 30
15 using namespace std;
16 
17 void run()
18 {
19     char s[100], str[100];
20     while(~scanf("%s", s))
21     {
22         if(!strcmp(s, "#"))
23             break;
24         int len = strlen(s);
25         strcpy(str, s);
26         sort(str, str+len);
27         next_permutation(s, s+len);
28         if(!strcmp(str, s))
29             printf("No Successor\n");
30         else
31             printf("%s\n", s);
32     }
33 }
34 
35 int main(void)
36 {
37     run();
38 
39     return 0;
40 }
ID Codes

 

 

转载于:https://www.cnblogs.com/Silence-AC/p/3462077.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值