Advertisement
Eather

Finding subsets

Jun 10th, 2011
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. # include <algorithm>
  2. # include <iostream>
  3. # include <cstdio>
  4. # include <cmath>
  5. # include <cstdlib>
  6. # include <map>
  7. # include <cmath>
  8. # include <vector>
  9. # include <cstring>
  10.  
  11. using namespace std;
  12.  
  13. # define FOR(i, a, b) for (int i=a; i<b; i++)
  14. # define REP(i, a) FOR(i,0,a)
  15. # define all(c) (c).begin(), (c).end()
  16. # define sz(x) x.size()
  17. # define pb push_back
  18. # define UNQ(s) {sort(all(s));(s).erase(unique(all(s)),s.end());}
  19. # define VS vector<string>
  20. # define rive(s) reverse(s.begin(),s.end())
  21.  
  22. VS Customers,List,lists;
  23. map<string,int>Candidate;
  24.  
  25. //checking the frequent number of subsets
  26.  
  27. //finding Subsets
  28. long pow(long a,long b)     /*finds a power of b*/
  29. {
  30. long i,j=1;
  31. for(i=1;i<=b;i++)
  32. j*=a;
  33. return j;
  34. }
  35.  
  36. long bin(int n)            /*converts into binary equivalent */
  37. {
  38. long i=0,j=1,r;
  39. while(n)
  40. {
  41. r=n%2;
  42. i=i+r*j;
  43. n/=2;
  44. j*=10;
  45. }
  46. return i;
  47. }
  48.  
  49. void sublist(string a)
  50. {
  51.     long i,j,k,m,l=0,n=0;
  52.  
  53.     while(a[l])
  54.     l++;
  55.     string ss="";VS final;
  56.     for(i=1;i<pow(2,l);i++)
  57.     {
  58.         k=bin(i);
  59.         m=l-1;
  60.  
  61.         while(m>=0)
  62.         {
  63.             j=k/pow(10,m);
  64.             if(j==1)
  65.                 ss.pb(a[l-1-m]);
  66.             k=k%pow(10,m);
  67.             m--;
  68.         }
  69.         final.pb(ss);
  70.         ss.clear();
  71.     }
  72.     REP(i,sz(final))cout<<final[i]<<endl;
  73. }
  74.  
  75. int main()
  76. {
  77.     string a;cin>>a;sublist(a);
  78. cout<<"\n\n\n\n\n\n\nDesigned by Iftekhar ahmed eather,\nStudent of CSE (07 batch),\nBUBT, Mirpur";
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement