Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1758215
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: C/C++

2011-10-08 18:54:50

  1. #include <ctype.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <assert.h>
  5. #include <string.h>
  6. #define OK 0
  7. #define MAXLINE 100
  8. int count=0;
  9. void powerSet(int,int,char *,char *);
  10. int main(int argc,char ** argv){
  11. printf("the input set is :{a,b,c}\r\n");
  12. printf("the powerset of the set is \r\n");
  13. powerSet(0,3,"","abc");
  14. printf("the number of the powerset is %d \r\n",count);
  15. getchar();
  16. return OK;
  17. }
  18. void powerSet(int index, int total, char * p, char *a){
  19. char buf[MAXLINE];
  20. assert(a);
  21. assert(p);
  22. if( index == 3){
  23. printf("{%s}\r\n",p);
  24. count++;
  25. }else{
  26. strcpy(buf,p);
  27. powerSet(index+1,3,buf,a);
  28. sprintf(buf,"%s %c ",p,a[index]);
  29. powerSet(index+1,3,buf,a);
  30. }
  31. }

阅读(1258) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~