#include <iostream>
#include <map>
#include <set>
#include<algorithm>
#include <iterator>
using namespace std;
int main() {
// your code goes here
/*string data[5][5] = { {"A","B","FG","C","D"} ,
{"B","G","D"},
{"B","F","G","AB"},
{"F","AB","C","D"},
{"A","BC","G","F","DE"}
};
int min_support = 2;
set<char> unique_events; // sets hold unique values
map<char, int> unique_support; // map each unique value to it's support
for (int row = 0; row < 5; row++) {
for (int col = 0; col < 5; col++) {
for (int s = 0; s < data[row][col].length(); s++) {
// looping over the dataset to insert unique events into the set
unique_events.insert(data[row][col][s]);
}
}
}
set<char> ::iterator it;
map<char, int> ::iterator t;
map<char, int> ::iterator loop;
// iterating over each event in the set comparing it to the row in the dataset
// (whether it appeared n the row or not) if yes, break from that row incrementing it's support
// in the map
for (it = unique_events.begin(); it != unique_events.end(); it++) {
for (int row = 0; row < 5; row++) {
bool found = false;
for (int col = 0; col < 5; col++) {
for (int s = 0; s < data[row][col].length(); s++) {
if (*it == data[row][col][s]) {
//searching for the event in the map exists or not
t = unique_support.find(data[row][col][s]);
if (t != unique_support.end())
t->second++;
else
unique_support.insert(pair<char,int>(data[row][col][s],1));
found = true;
}
if (found)
break;
}
if (found)
break;
}
}
}
/// pruning support
for (t = unique_support.begin(); t != unique_support.end(); ) {
if (t->second < min_support) {
loop = t;
unique_events.erase(t->first);
t++;
unique_support.erase(loop); // if support < min_support , delete from the map
}
else
t++;
}
////// CANDIDATE GENERATION OF SIZE 2
set<string> candidatesSize2;
//string candidatesSize2[100];
set<char> ::iterator item1;
set<char> ::iterator item2;
int i = 0;
for (item1 = unique_events.begin(); item1 != unique_events.end(); item1++) {
for (item2 = unique_events.begin(); item2 != unique_events.end(); item2++) {
string a, b;
a.append(1, *item1);
b.append(1, *item2);
string h = a + ' '+ b;
candidatesSize2.insert(h);
}
}
for (item1 = unique_events.begin(); item1 != unique_events.end(); item1++) {
it = item1;
for (item2 = ++it; item2 != unique_events.end(); item2++) {
//cout << *it << endl;
//cout << *item1 << " " << *item2 << endl;
string a, b;
a.append(1, *item1);
b.append(1, *item2);
string h = a + b;
candidatesSize2.insert(h);
}
}
*/
set<string> ::iterator item11;
set<string> ::iterator item22;
set<string> candidatesSize3;
set<string> candidatesSize2;
candidatesSize2.insert("b b");
candidatesSize2.insert("a b");
candidatesSize2.insert("b c");
candidatesSize2.insert("c b");
candidatesSize2.insert("bd");
candidatesSize2.insert("d b");
candidatesSize2.insert("b e");
candidatesSize2.insert("d c");
candidatesSize2.insert("ce");
for (item11 = candidatesSize2.begin(); item11 != candidatesSize2.end(); item11++) {
for (item22 = candidatesSize2.begin(); item22 != candidatesSize2.end(); item22++) {
string a, b, c;
string i1=*item11,i2=*item22;
if(i1==i2)
continue;
if (i1.size() == 3&& i2.size() == 3)
{
if (i1[2] == i2[0])
{
a.append(1, i1[0]);
b.append(1, i2[0]);
c.append(1, i2[2]);
string h = a + ' ' + b + ' ' + c;
candidatesSize3.insert(h);
}
}
else if (i1.size() == 3&& i2.size() == 2)
{
if (i1[2] == i2[0])
{
a.append(1, i1[0]);
b.append(1, i2[0]);
c.append(1, i2[1]);
string h = a + ' ' + b + c;
candidatesSize3.insert(h);
}
}
else if (i1.size() == 2&& i2.size() == 3)
{
if (i1[1] == i2[0])
{
a.append(1, i1[0]);
b.append(1, i2[0]);
c.append(1, i2[2]);
string h = a + b + ' ' + c;
candidatesSize3.insert(h);
}
}
else
{
if (i1[1] == i2[0])
{
a.append(1, i1[0]);
b.append(1, i2[0]);
c.append(1, i2[1]);
string h = a + b + c;
candidatesSize3.insert(h);
}
}
}
}
set<string> ::iterator sz;
for (sz = candidatesSize3.begin(); sz != candidatesSize3.end(); sz++) {
cout << *sz << endl;
}
set<string> ::iterator item3;
// set<string> c1=candidatesSize3.begin();
set<string> it1 = candidatesSize3;
//set<string> c2=candidatesSize3.end();
// string::iterator it2 = candidatesSize3.end();
for (item3= it1.begin(); item3 != it1.end(); item3++)
{
string a, b, c;
string s = *item3;
if(s.size()==5)//A B C
{
a.append(1, s[0]);
b.append(1, s[2]);
c.append(1, s[4]);
string subseq1=a+' '+b;
string subseq2=b+' '+c;
string subseq3=a+' '+c;
bool is_in = (candidatesSize2.find(subseq1) != candidatesSize2.end())&&
(candidatesSize2.find(subseq2) != candidatesSize2.end())&&
(candidatesSize2.find(subseq3) != candidatesSize2.end());
if(!is_in)
{
candidatesSize3.erase(candidatesSize3.find(s));
}
}
else if (s.size()==4)
{
if(s[2]==' ') //AB C
{
a.append(1, s[0]);
b.append(1, s[1]);
c.append(1, s[3]);
string subseq1=a+b;
string subseq2=b+' '+c;
string subseq3=a+' '+c;
bool is_in = (candidatesSize2.find(subseq1) != candidatesSize2.end())&&
(candidatesSize2.find(subseq2) != candidatesSize2.end())&&
(candidatesSize2.find(subseq3) != candidatesSize2.end());
if(!is_in)
candidatesSize3.erase(candidatesSize3.find(s));
}
if(s[1]==' ')//A BC
{
a.append(1, s[0]);
b.append(1, s[2]);
c.append(1, s[3]);
string subseq1=a+' '+b;
string subseq2= b + c ;
string subseq3=a +' '+c;
bool is_in = (candidatesSize2.find(subseq1) != candidatesSize2.end())&&
(candidatesSize2.find(subseq2) != candidatesSize2.end())&&
(candidatesSize2.find(subseq3) != candidatesSize2.end());
if(!is_in)
candidatesSize3.erase(candidatesSize3.find(s));
}
}
else //ABC
{
a.append(1, s[0]);
b.append(1, s[1]);
c.append(1, s[2]);
string subseq1=a+b;
string subseq2=b+c;
string subseq3=a+c;
bool is_in = (candidatesSize2.find(subseq1) != candidatesSize2.end())&&
(candidatesSize2.find(subseq2) != candidatesSize2.end())&&
(candidatesSize2.find(subseq3) != candidatesSize2.end());
if(!is_in)
candidatesSize3.erase(candidatesSize3.find(s));
}
}
cout<<"-------------------------------------"<<endl;
set<string> ::iterator sz1;
for (sz1 = candidatesSize3.begin(); sz1 != candidatesSize3.end(); sz1++) {
cout << *sz1 << endl;
}
return 0;
}