Advertisement
Eather

datamining_lab1

Jun 9th, 2011
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 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. int chk(string s)
  27. {
  28.     int cnt=0;
  29.     REP(i,sz(Customers))
  30.     {   int l=0;
  31.         REP(j,sz(Customers[i]))
  32.         {
  33.             if(Customers[i][j]==s[l]){l++;}
  34.         }
  35.         if(l==sz(s))cnt++;
  36.     }
  37.     return cnt;
  38. }
  39. int min_sup;
  40.  
  41. //finding Subsets
  42. void sublist(string array)
  43. {
  44.     int numOfSubsets = 1 << array.size();
  45.     string ss="";
  46.     for(int i = 0; i < numOfSubsets; i++)
  47.     {
  48.         int pos = array.size() - 1;
  49.         int bitmask = i;
  50.         while(bitmask > 0)
  51.         {
  52.             if((bitmask & 1) == 1)ss.pb(array[pos]);
  53.             bitmask >>= 1;
  54.             pos--;
  55.         }sort(all(ss));
  56.         if(chk(ss)>=min_sup){
  57.             Candidate[ss]=chk(ss);
  58.             lists.pb(ss);
  59.         }
  60.         ss.clear();
  61.     }
  62. }
  63.  
  64. int main()
  65. {
  66.     string Items;
  67.  
  68.     while(1)
  69.     {
  70.         getline(cin,Items);if(sz(Items)==0)break;
  71.         string s;
  72.         REP(i,sz(Items))if(isalpha(Items[i]))s+=Items[i];
  73.         Customers.pb(s);s.clear();
  74.     }
  75.     cout<<"What is your minimum support? ";
  76.     cin>>min_sup;
  77.  
  78.     string starting_list;
  79.     map<char,int>cn;
  80.  
  81.     REP(i,sz(Customers))
  82.     {
  83.         sort(all(Customers[i]));UNQ(Customers[i]);
  84.         REP(j,sz(Customers[i]))
  85.         {
  86.             cn[Customers[i][j]]++;
  87.             if(cn[Customers[i][j]]>=min_sup)starting_list.pb(Customers[i][j]);
  88.         }
  89.     }
  90.     sort(all(starting_list));UNQ(starting_list);
  91.  
  92.     //check the subsets and push_back
  93.     sublist(starting_list);
  94.  
  95.     VS res;int szz=0;
  96.     REP(i,sz(lists)){
  97.        /*Print to see the lists of the succesive Items name*/ //cout<<lists[i]<<" "<<Candidate[lists[i]]<<endl;
  98.         if(Candidate[lists[i]]>=min_sup)
  99.             res.pb(lists[i]),szz=max(szz,(int)sz(lists[i]));}
  100.     UNQ(res);
  101.     REP(i,sz(res))
  102.         if(sz(res[i])==szz)cout<<res[i]<<endl;
  103.  
  104.     //clear all
  105.     {Customers.clear();List.clear();Candidate.clear();lists.clear();starting_list.clear();cn.clear();}
  106. cout<<"\n\n\n\n\n\n\nDesigned by Iftekhar ahmed eather,\nStudent of CSE (07 batch),\nBUBT, Mirpur";
  107.     return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement