题意:求输入字符串的所有组合,按字典序输出!

解法:使用枚举(枚举前先找出最字符串的最小字典序)枚举时加上枚举生成条件!

 #include <iostream>
#include <string>
#include <algorithm>
using namespace std; bool comp(char ch1,char ch2){
if(ch1 - ch2 == ){
return false;
}
if (ch2 - ch1 == ){
return true;
}
if(ch1 >= 'a' && ch2 <='Z')
{
return ch1 - < ch2;
}
else if(ch1 <='Z' && ch2 >= 'a')
{
return ch1 + < ch2;
}
else{
return ch1 < ch2;
} }
// comp() below can also meet our need
/**
int compute(char ch){
if(ch>='a' && ch<='z')
return (ch-'a')*2 +1;
else if(ch>='A' && ch<='Z')
return (ch-'A')*2;
else
return 0;
}
bool comp(char ch1,char ch2){
return compute(ch1)<compute(ch2);
}
**/
int main()
{
int in,n;
cin>>in; while(in--)
{
string s;
cin>>s;
n=s.length();
sort(s.begin(),s.end(),comp);
do{
cout<<s<<endl;
//字典序要注意加入comp()生成条件
}while(next_permutation(s.begin(),s.end(),comp));
}
return ;
}

UVA 195 Anagram的更多相关文章

  1. uva 10825 - Anagram and Multiplication(暴力)

    题目链接:uva 10825 - Anagram and Multiplication 题目大意:给出m和n,要求找一个m位的n进制数,要求说该数乘以2~m中的随意一个数的结果是原先数各个位上数值的一 ...

  2. UVA - 10825 Anagram and Multiplication

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34594 有一个m位n进制的数,它的特性是这个数依次乘以2,3... ...

  3. Fast Matrix Operations(UVA)11992

    UVA 11992 - Fast Matrix Operations 给定一个r*c(r<=20,r*c<=1e6)的矩阵,其元素都是0,现在对其子矩阵进行操作. 1 x1 y1 x2 y ...

  4. [LeetCode] Valid Anagram 验证变位词

    Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...

  5. Leetcode Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  6. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  7. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  8. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  9. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

随机推荐

  1. 经典算法:快排的Javascript版本

    function swap(arr,l,r){ var temp=arr[l]; arr[l]=arr[r]; arr[r]=temp; } function partition(arr,camp,l ...

  2. C# 将MSMQ消息转换成Json格式 【优化】

    C# 将MSMQ消息转换成Json格式  [优化] 转换函数: private string ConvertToJSON(string label, string body) { //TODO: co ...

  3. C#获取窗口,模拟按键操作

    C#获取窗口,模拟按键操作,实现计算器模拟操作.首先引用. using System.Runtime.InteropServices; 使用DllImport引入两个函数: // Get a hand ...

  4. SQL 结构化查询语言手册

    摘自该学习网站: http://www.w3school.com.cn/sql/ 新学到的几点: and 和or 连用,记得用括号.                2.SQL通配符补充   例如:   ...

  5. 配置PPTP服务器

    1.验证内核是否加载了MPPE模块: modprobe ppp-compress-18 && echo MPPE is ok 2.安装所需的软件包: yum -y install pp ...

  6. systemd添加自定义系统服务设置自定义开机启动

    1.服务权限 systemd有系统和用户区分:系统(/user/lib/systemd/system/).用户(/etc/lib/systemd/user/).一般系统管理员手工创建的单元文件建议存放 ...

  7. 一位学长的ACM总结(感触颇深)

    发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...

  8. String[]和ArrayList和LinkedList区别

    String[]和ArrayList和LinkedList区别 参考文档如下: http://www.blogjava.net/flysky19/articles/92775.html http:// ...

  9. (转)js获取url参数值

    明天有空编辑下 今天做项目遇到js取得url地址问号后面的参数,找了下面的,用着非常好,项目是选项卡样式的,也就是一点击二级分类,底下的同样名字的背景变红(选项卡倍选中) http://www.cnb ...

  10. 使用URL读取网络图片资源

    URL(Uniform Resource Locator) 对象代表统一资源定位器. 代码如下: public class MainActivity extends ActionBarActivity ...