擅长排列的小明 string(stl)的应用 + 排列
2014-06-26 15:06
190 查看
题目来源:http://acm.nyist.net/JudgeOnline/problem.php?pid=19
难度:4
描述小明十分聪明,而且十分擅长排列计算。比如给小明一个数字5,他能立刻给出1-5按字典序的全排列,如果你想为难他,在这5个数字中选出几个数字让他继续全排列,那么你就错了,他同样的很擅长。现在需要你写一个程序来验证擅长排列的小明到底对不对。
输入第一行输入整数N(1<N<10)表示多少组测试数据,
每组测试数据第一行两个整数 n m (1<n<9,0<m<=n)输出在1-n中选取m个字符进行全排列,按字典序全部输出,每种排列占一行,每组数据间不需分界。如样例样例输入
样例输出
擅长排列的小明
时间限制:1000 ms | 内存限制:65535 KB难度:4
描述小明十分聪明,而且十分擅长排列计算。比如给小明一个数字5,他能立刻给出1-5按字典序的全排列,如果你想为难他,在这5个数字中选出几个数字让他继续全排列,那么你就错了,他同样的很擅长。现在需要你写一个程序来验证擅长排列的小明到底对不对。
输入第一行输入整数N(1<N<10)表示多少组测试数据,
每组测试数据第一行两个整数 n m (1<n<9,0<m<=n)输出在1-n中选取m个字符进行全排列,按字典序全部输出,每种排列占一行,每组数据间不需分界。如样例样例输入
2 3 1 4 2
样例输出
1 2 3 12 13 14 21 23 24 31 32 34 41 42 43 分析:string substr(local,count) 标志的起始位置,和 计数值 代码如下:
#include <cstdlib> #include <cstring> #include <algorithm> #include <cstdio> #include <cmath> #include <iostream> #include <vector> #include<set> #include<queue> using namespace std; typedef long long ll; int main() { int t; cin>>t; while(t--) { string s1,s2; int x,y; cin>>x>>y; for(int i=1;i<=x;i++) s1+=i+'0'; s2=s1.substr(0,y); cout<<s2<<endl; while(next_permutation(s1.begin(),s1.end())) { if(s2!=s1.substr(0,y)) { s2=s1.substr(0,y); cout<<s2<<endl; } } } return 0; }
相关文章推荐
- nyoj19擅长排列的小明(STL)&&(DFS)
- NYOJ 19 擅长排列的小明 (STL之next_permutation()的使用)
- NY19 擅长排列的小明 【STL】
- 擅长排列的小明 DFS()和 STL两种方法
- 擅长排列的小明STL
- (STL) ACM_擅长排列的小明.(补)
- NYOJ - 19 - 擅长排列的小明(STL - set +全排列)
- [南阳]-19 擅长排列的小明 [STL/DFS]
- nyoj19擅长排列的小明(DFS或STL)
- NYOJ19,擅长排列的小明,StringBuffer.deleteCharAt()
- 擅长排列的小明 STL
- 擅长排列的小明 II
- NYOJ 469 擅长排列的小明 II
- 擅长排列的小明 南工19
- 擅长排列的小明
- NYOJ_469_擅长排列的小明 II
- NYOJ 469 擅长排列的小明 II
- NYOJ 19-擅长排列的小明
- NYIST469-擅长排列的小明(2)
- NYOJ-19 擅长排列的小明 -----回溯