syhd142  
日历
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
统计
  • 随笔 - 23
  • 文章 - 122
  • 评论 - 31
  • 引用 - 0

导航

常用链接

留言簿(2)

随笔档案(23)

文章分类(270)

文章档案(122)

我的豆瓣

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 
题目很简单,生成字母顺序的时候不会弄,代码能力还是不行。
#include <stdio.h>
#include 
<string>
#include 
<map>
using namespace std;

char word[27= "abcdefghijklmnopqrstuvwxyz";
bool mk[27]; 
map
<stringint> hash;
int num;

void build(int pos, int deep)
{
    
if(!deep)
    {
        num
++;
        
char tmp[6];
        
int len = 0;
        
for(int i = 0; i < 26; i++)
        {
            
if(mk[i]) tmp[len++= word[i];
        }
        tmp[len] 
= 0;
    
//    printf("%s\n", tmp);
    
//    system("pause");
        hash[(string)tmp] = num;
        
return;
    }
    
if(pos >= 26return;
    mk[pos] 
= 1;
    build(pos 
+ 1, deep - 1);
    mk[pos] 
= 0;
    build(pos 
+ 1, deep);
}

int main()
{
    num 
= 0;
    
for(int i = 1; i < 6; i++) build(0, i);
    
char data[6];
    
while(gets(data)) printf("%d\n", hash[data]);
    
return 0;

posted on 2010-10-06 19:40 Fucker 阅读(583) 评论(0)  编辑 收藏 引用 所属分类: ACM/ICPC简单字符串

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


 
Copyright © Fucker Powered by: 博客园 模板提供:沪江博客