Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <algorithm>
- # include <iostream>
- # include <cstdio>
- # include <cmath>
- # include <cstdlib>
- # include <map>
- # include <cmath>
- # include <vector>
- # include <cstring>
- using namespace std;
- # define FOR(i, a, b) for (int i=a; i<b; i++)
- # define REP(i, a) FOR(i,0,a)
- # define all(c) (c).begin(), (c).end()
- # define sz(x) x.size()
- # define pb push_back
- # define UNQ(s) {sort(all(s));(s).erase(unique(all(s)),s.end());}
- # define VS vector<string>
- # define rive(s) reverse(s.begin(),s.end())
- VS Customers,List,lists;
- map<string,int>Candidate;
- //checking the frequent number of subsets
- int chk(string s)
- {
- int cnt=0;
- REP(i,sz(Customers))
- { int l=0;
- REP(j,sz(Customers[i]))
- {
- if(Customers[i][j]==s[l]){l++;}
- }
- if(l==sz(s))cnt++;
- }
- return cnt;
- }
- int min_sup;
- //finding Subsets
- void sublist(string array)
- {
- int numOfSubsets = 1 << array.size();
- string ss="";
- for(int i = 0; i < numOfSubsets; i++)
- {
- int pos = array.size() - 1;
- int bitmask = i;
- while(bitmask > 0)
- {
- if((bitmask & 1) == 1)ss.pb(array[pos]);
- bitmask >>= 1;
- pos--;
- }sort(all(ss));
- if(chk(ss)>=min_sup){
- Candidate[ss]=chk(ss);
- lists.pb(ss);
- }
- ss.clear();
- }
- }
- int main()
- {
- string Items;
- while(1)
- {
- getline(cin,Items);if(sz(Items)==0)break;
- string s;
- REP(i,sz(Items))if(isalpha(Items[i]))s+=Items[i];
- Customers.pb(s);s.clear();
- }
- cout<<"What is your minimum support? ";
- cin>>min_sup;
- string starting_list;
- map<char,int>cn;
- REP(i,sz(Customers))
- {
- sort(all(Customers[i]));UNQ(Customers[i]);
- REP(j,sz(Customers[i]))
- {
- cn[Customers[i][j]]++;
- if(cn[Customers[i][j]]>=min_sup)starting_list.pb(Customers[i][j]);
- }
- }
- sort(all(starting_list));UNQ(starting_list);
- //check the subsets and push_back
- sublist(starting_list);
- VS res;int szz=0;
- REP(i,sz(lists)){
- /*Print to see the lists of the succesive Items name*/ //cout<<lists[i]<<" "<<Candidate[lists[i]]<<endl;
- if(Candidate[lists[i]]>=min_sup)
- res.pb(lists[i]),szz=max(szz,(int)sz(lists[i]));}
- UNQ(res);
- REP(i,sz(res))
- if(sz(res[i])==szz)cout<<res[i]<<endl;
- //clear all
- {Customers.clear();List.clear();Candidate.clear();lists.clear();starting_list.clear();cn.clear();}
- cout<<"\n\n\n\n\n\n\nDesigned by Iftekhar ahmed eather,\nStudent of CSE (07 batch),\nBUBT, Mirpur";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement