T9的空间

You will never walk alone!

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  69 随笔 :: 0 文章 :: 28 评论 :: 0 Trackbacks
这里有对全排列函数permutation的介绍http://hi.baidu.com/sunshine_0316/blog/item/6f87a044bf30f320cffca381.html
#include<iostream>
#include
<map>
#include
<algorithm>

using namespace std;

typedef 
struct node
{
    
char ch;
    
int flag;
}
node;

bool cmp(const node a,const node b)
{
    
return a.flag<b.flag;
}


int main()
{
    
int cas,i;
    
char str[15],ch;
    map
<char,int> mp;
    
for(ch='A',i=1;ch<='Z';ch++,i=i+2) mp[ch]=i;
    
for(ch='a',i=2;ch<='z';ch++,i=i+2) mp[ch]=i;
    scanf(
"%d",&cas);
    
while(cas--)
    
{
        scanf(
"%s",str);
        
int len=strlen(str);
        node p[
15];
        
for(i=0;i<len;i++)
        
{
            p[i].ch
=str[i];
            p[i].flag
=mp[str[i]];
        }

        sort(p,p
+len,cmp);
        
do
        
{
            
for(i=0;i<len;i++)
                printf(
"%c",p[i].ch);
            printf(
"\n");
        }
while(next_permutation(p,p+len,cmp));
    }

    
return 0;
}


posted on 2008-09-10 11:32 Torres 阅读(947) 评论(0)  编辑 收藏 引用 所属分类: Number Theory

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理