• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Hug_Sea
博客园    首页    新随笔    联系   管理    订阅  订阅

POJ-1256 Anagram

题意:给出一字符串,求出所有按字母顺序排序的全排列。

思路:STL库函数-next_permutation(),全排列函数。

题目链接:http://poj.org/problem?id=1256

 

View Code
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <string>
 5 #include <algorithm>
 6 #include <iostream>
 7 using namespace std;
 8 const int N=14;
 9 
10 char str[N];
11 
12 bool cmp(char c1,char c2){
13     if(tolower(c1)==tolower(c2))
14         return c1<c2;
15     else return tolower(c1)<tolower(c2);    //toupper 转换为大写字母 
16 }
17 
18 int main(){
19     
20 //    freopen("data.in","r",stdin);
21 //    freopen("data.out","w",stdout);
22     
23     int t;
24     scanf("%d",&t);
25     while(t--){
26         scanf("%s",str);
27         int len=strlen(str);
28         sort(str,str+len,cmp);
29         do{
30             printf("%s\n",str);
31         }while(next_permutation(str,str+len,cmp));
32     }
33     return 0;
34 }
posted @ 2012-06-04 19:49  Hug_Sea  阅读(159)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3