week11_

Generating permutation has always been an important problem in computer science. In this problem you will have to generate the permutation of a given string in ascending order. Remember that your algorithm must be efficient.

Input

The first line of the input contains an integer n, which indicates how many strings to follow. The next n lines contain n strings. Strings will only contain alpha numerals and never contain any space. The maximum length of the string is 10.

Output

For each input string print all the permutations possible in ascending order. Not that the strings should be treated, as case sensitive strings and no permutation should be repeated. A blank line should follow each output set.

Sample Input

3

ab

abc

bca

Sample Output

ab

ba

 

abc

acb

bac

bca

cab

cba

 

abc

acb

bac

bca

cab

cba

核心思想:全排列 

知识要求:prev_permutation(S,S+Len);next_prepermutation(S,S+Len)函数

sort()函数

 

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
//bool cmp2(char a,char b){
//	return a>b;
//}从大到小排序

bool cmp1(char a,char b){
	return a<b;
} //从小到大排序 
int main()
{
	int t,i,j,k,q,tmp;
	int N=10;//总的个数 
    scanf("%d\n",&n);
    char s[N+1];
    
	while(n--)
	{
		gets(s);
		sort(s,s+strlen(s),cmp1);
//字典排序,从小到大,cmp1:next_permutation(S,S+Len);cmp2,从大到小,
//prev_permutation(S,S+Len) 
		do{
			puts(s);
		}while(next_permutation(s,s+strlen(s)));
		printf("\n");
}

	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
springboot+MyBatis连接MySql数据库遇到问题:### Error querying database. Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet successfully received from the server was 11,751 milliseconds ago. The last packet sent successfully to the server was 11,858 milliseconds ago. ### The error may exist in file [/app/tomcat/webapps/project/WEB-INF/classes/mapper/PersonWeekMapper.xml] ### The error may involve com.xmsme.mapper.PersonWeekMapper.selectPersonWeekList-Inline ### The error occurred while setting parameters ### SQL: SELECT count(0) FROM (SELECT WEEK.id, WEEK.sub_time, WEEK.need_thing, WEEK.plan_content, WEEK.target_content, WEEK.sub_time AS update_time, WEEK.create_time, WEEK.week_start, WEEK.user_id, WEEK.week_end, readInfo.id AS readId, readInfo.read_status AS readStatus, updateor.nick_name FROM t_person_weekly AS WEEK LEFT JOIN sys_user sUser ON sUser.user_id = WEEK.user_id LEFT JOIN t_read_info readInfo ON readInfo.business_id = WEEK.id AND readInfo.read_type = 'PER' LEFT JOIN sys_user updateor ON updateor.user_id = WEEK.update_by LEFT JOIN sys_user_role uRole ON uRole.user_id = WEEK.update_by LEFT JOIN sys_user_post uPost ON uPost.user_id = WEEK.user_id LEFT JOIN t_project_person person ON person.user_id = WEEK.user_id LEFT JOIN t_project_person Pperson ON Pperson.project_id = person.project_id WHERE 1 = 1 AND WEEK.is_del = 0 AND WEEK.draft = 'N' AND Pperson.user_id = ? GROUP BY WEEK.id) table_count ### Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet successfully received from the server was 11,751 milliseconds ago. The last packet sent successfully to the server was 11,858 milliseconds ago. ; Communications link failure The last packet successfully received from the server was 11,751 milliseconds ago. The last packet sent successfully to the server was 11,858 milliseconds ago.; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet successfully received from the server was 11,751 milliseconds ago. The last packet sent successfully to the server was 11,858 milliseconds ago.
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值