原题:
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

中文:
给你一个字符串,让你输出这个字符串按字典序的所有排列。

代码:

#include<bits/stdc++.h>
using namespace std;typedef long long ll;
const int maxn=11;char s[maxn],ans[maxn];void permutation(int n,int cur,char *p,char *a)
{if(cur==n){for(int i=0;i<n;i++)cout<<a[i];cout<<endl;}else{for(int i=0;i<n;i++){if(!i||p[i]!=p[i-1]){int c1=0,c2=0;for(int j=0;j<cur;j++)if(a[j]==p[i])c1++;for(int j=0;j<n;j++)if(p[j]==p[i])c2++;if(c1<c2){a[cur]=p[i];permutation(n,cur+1,p,a);}}}}
}int main()
{ios::sync_with_stdio(false);int t;cin>>t;while(t--){cin>>s;int len=strlen(s);sort(s,s+len);permutation(len,0,s,ans);//if(t)cout<<endl;}return 0;
}

解答:

裸题,套小白书里的模板即可

uva 10098 Generating Fast相关推荐

  1. uva 10098 Generating Fast(全排列)

    还是用的两种方法,递归和STL,递归那个是含有反复元素的全排列,这道题我 没有尝试没有反复元素的排列,由于从题目上并没有发现一定是有反复元素的() 贴代码: <span style=" ...

  2. 【UVA】11992 - Fast Matrix Operations(段树模板)

    主体段树,要注意,因为有set和add操作,当慵懒的标志下推.递归优先set,后复发add,每次运行set行动add马克清0 WA了好几次是由于计算那一段的时候出问题了,可笑的是我对着模板找了一个多小 ...

  3. uva 11925——Generating Permutations

    题意:给定一个1-n的排列,用不超过2*n2的操作把他变成升序.每次操作只有两种,一种是交换前两个元素,另外一种是把最后一个元素放到最后一位. 思路:贪心.用双端队列来保存数据,每次当v[0]> ...

  4. π-Algorithmist分类题目(1)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...

  5. 提取了下刘汝佳推荐的题号...

    今天闲来没事上uva oj提取了下刘汝佳推荐的acm题号,原始数据如下: Volume 0. Getting Started    10055 - Hashmat the Brave Warrior ...

  6. ICPC训练联盟2021寒假冬令营(9)_2021.01.29_笔记

    试题链接 点我进入代码提交OJ 学习笔记 - 数论与组合分析入门 数论的编程实验 • 3.1素数运算的实验范例 • 3.2求解不定方程和同余方程的实验范例 • 3.3 特殊的同余式 • 3.4 积性函 ...

  7. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  8. AOAPC I: Beginning Algorithm Contests 题解

    AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...

  9. ICPC程序设计题解书籍系列之六:吴永辉:《算法设计编程实验》

    第1章 Ad Hoc问题 POJ2661 HDU1141 ZOJ2545 UVA10916 Factstone Benchmark[Ad Hoc] UVA10037 Bridge[贪心] POJ257 ...

  10. 紫书《算法竞赛入门经典》

    紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...

最新文章

  1. 阿里2018营收2502亿元,云计算业务增幅超100%
  2. java poi 更新excel_在Java Apache POI中更新现有的Excel文件
  3. 计算机应用大一题,大一计算机应用基础习题与答案(精选).doc
  4. mysql空间是什么格式_MySQL数据类型 - 空间数据类型 (6)
  5. 计算机配置型号及主要技术指标,显卡性能看什么参数(新手必备的显卡性能知识全解)...
  6. 移动端键盘弹起导致底部按钮上浮解决方案
  7. 常用的Opencv函数汇总(持续更新...)
  8. 计算机科学与技术a类学科,清华大学a类学科有哪些?附清华a类学科名单
  9. 数字IC设计流程总结
  10. canal与mysql高可用_canal 高可用介绍(4)
  11. mysql 使用gzip 压缩 文件,本地对 gzip 压缩的文件解压缩
  12. python应用学习(五)——requests爬取网页图片
  13. JavaScript世界各地时间转换为北京时间
  14. Java空格算不算字符串长度_计算字符串尾部空格长度
  15. VMware Workstation的安装
  16. redis.conf文件下载与配置
  17. 使用pycharm搭建数据库模型
  18. 学计算机颈椎,长期玩电脑颈椎病
  19. 深度学习 pytorch cifar10数据集训练
  20. 交互设计:界面设计尺寸详解与常用尺寸

热门文章

  1. 机器学习综述论文笔记:Machine Learning: A Review of Learning Types
  2. Django教程 —— 站点后台管理
  3. 十五、移动端vw+rem等比缩放布局开发的详细步骤:包含px与rem的单位换算、二倍图以及如何使用UI给的设计稿等(开发工具HBuilder)
  4. “DAO”是什么?从Web发展详细解析什么是DAO
  5. uc android快捷键,UC手机浏览器助力Android快速上网
  6. keyshot渲染图文教程_使用keyshot渲染器精确贴图的步骤教程详解
  7. cad卸载不干净_【实用】流氓软件卸载不干净?
  8. 最新iPhone X设计规范,详细完整的了解IOS设计规范。
  9. 如何选择深度学习的GPU
  10. 7个必备网站,查征信、查三无产品、查老赖、查犯罪记录!