扑克序列
2016-03-17 21:49
260 查看
A A 2 2 3 3 4 4, 一共4对扑克牌。请你把它们排成一行。 要求:两个A中间有1张牌,两个2之间有2张牌,两个3之间有3张牌,两个4之间有4张牌。 请填写出所有符合要求的排列中,字典序最小的那个。
例如:22AA3344 比 A2A23344 字典序小。当然,它们都不是满足要求的答案。
请通过浏览器提交答案。“A”一定不要用小写字母a,也不要用“1”代替。字符间一定不要留空格。
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; bool test(char s[],char c,int cnt){ int i,j; for(i=0;i<8;i++){ if(s[i]==c){ for(j=i+1;j<8;j++){ if(s[j]==c&&(j-i)==cnt){ return true; } } } } return false; } int main(){ char s[8]={'A','A','4','4','3','3','2','2'}; int i; char p[8]={'A','A','2','2','3','3','4','4'}; while(prev_permutation(s,s+8)){ // for(i=0;i<8;i++){ // printf("%c",s[i]); // } //printf("\n"); if(test(s,'A',2)&&test(s,'2',3)&&test(s,'3',4)&&test(s,'4',5)){ if(strcmp(p,s)>0){ for(i=0;i<8;i++){ p[i]=s[i]; } } } } for(i=0;i<8;i++){ printf("%c",p[i]); } return 0; }
相关文章推荐
- 使用递归实现全排列输出
- Linux QtCreator 设置mingw编译器生成windows程序
- 【JDK源码分析】浅谈HashMap的原理
- Codeforces 405 E. Graph Cutting 【DFS 】
- JAVA流程控制语句
- [bzoj2965]保护古迹
- Python爬虫之模拟登录总结
- PPTController --第一次github尝试
- Apache2.4使用require指令进行访问控制--允许或限制IP访问/通过User-Agent禁止不友好网络爬虫
- 业务数据模型短暂思考整理
- Spring AOP 注解和xml实现 --转载
- Intellij IDEA 构建Spring Web项目 — 用户登录功能
- Future模式
- jsp 导航栏显示日期和星期几
- MVC过滤器详解
- 0317
- java读取properties文件的几种方法
- 任务四:定位和居中问题
- 二维树状数组
- 制作cpprefernce.chm