poj 1146 ID Codes
来源:互联网 发布:系统之家windows vista 编辑:程序博客网 时间:2024/05/17 21:02
ps
容朕吐槽一句:
每写一道题要是能查一遍生词,英语估计都不用愁了【没错说你呢poj
这是一道排列的题–隶属algorithm库里的 next_permutation。
引自cpluplus的example
// next_permutation example#include <iostream> // std::cout#include <algorithm> // std::next_permutation, std::sortint main () { int myints[] = {1,2,3}; std::sort (myints,myints+3); std::cout << "The 3! possible permutations with 3 elements:\n"; do { std::cout << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '\n'; } while ( std::next_permutation(myints,myints+3) ); std::cout << "After loop: " << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '\n'; return 0;}
样例输出】
The 3! possible permutations with 3 elements:
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
After loop: 1 2 3
按照STL文档的描述,next_permutation函数将按字母表顺序生成给定序列的下一个较大的排列,直到整个序列为降序为止。
另外还有一种排列是相反的:
prev_permutation函数与之相反,是生成给定序列的上一个较小的排列。二者原理相同,仅遍例顺序相反,
本题:
求该字符串的下一个排列,要是不存在的话,就输出No Successor
题很简单啦:一个应用。
#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;int main(){ char input[51]; while(scanf("%s",&input)!=EOF) { if(strcmp(input,"#") == 0) { break; } int len=strlen(input); if(next_permutation(input,input+len)) { printf("%s\n",input); } else printf("No Successor\n"); } return 0; }
0 0
- poj 1146 ID Codes
- POJ 1146 ID Codes
- poj 1146 ID Codes
- poj 1146 ID Codes
- POJ 1146 ID Codes
- POJ 1146:ID Codes
- poj 1146 ID Codes
- ID Codes POJ - 1146
- POJ 1146 ID Codes (STL)
- ACM POJ 1146 ID Codes
- ID Codes(poj 1146)
- POJ 1146 ID Codes 笔记
- UVa 146 & POJ 1146 - ID Codes
- POJ 1146 ID Codes(枚举排序)
- POJ 1146 ID Codes (生成排列)
- poj 1146 ID Codes(next_permutation)
- Poj 1146 ID Codes + Poj 1833 排列 (全排列库函数)
- POJ 1146 ID Codes 求下一个字典序
- 网易互娱2017实习生招聘在线笔试(二)
- JAVA多线程之(CyclicBarrier)
- Android实现仿qq登录可编辑下拉菜单
- 五、物理任务生成
- hdu2048 神、上帝以及老天爷(错排)
- poj 1146 ID Codes
- Codility K complementary pairs
- myeclipse2014如何创建user library
- java设计模式基础之设计原则
- ps快捷键(未完待续)
- KNN算法
- problemB
- Fast rcnn set up
- 葱油拌面的做法