Professional Documents
Culture Documents
Optimize The Given Code For Expected Output
Optimize The Given Code For Expected Output
Optimize The Given Code For Expected Output
#include<iostream>
using namespace std;
class A
{
public:
A ()
{ cout << "\n A's constructor"; }
A (const A &a)
{ cout << "\n A's Copy constructor"; }
A& operator= (const A &a)
{
if(this == &a) return *this;
cout << "\n A's Assignment Operator";
return *this;
}
};
class B
{
A a;
public:
B(A &a)
{ this->a = a; cout << "\n B's constructor"; }
};
int main()
{
A a1;
B b(a1);
return 0;
}
There are M transmitter and N receiver stations. Given a matrix that keeps track of the
number of packets to be transmitted from a given transmitter to a receiver. If the (i, j)-th
entry of the matrix is k, it means at that time the station i has k packets for transmission to
station j.
During a time slot, a transmitter can send only one packet and a receiver can receive only
one packet. Find the channel assignments so that maximum number of packets are
transferred from transmitters to receivers during the next time slot.
#include <iostream>
#include <string.h>
#include <vector>
#define M 3
#define N 3
using namespace std;
int main()
{
int table[M][N] = {{0, 2, 0}, {3, 0, 1}, {2, 4, 0}};
int max_flow = maxBPM(table);
return 0;
}
A Suffix Tree for a given text is a compressed trie for all suffixes of the given text.
A suffix array is a sorted array of all suffixes of a given string.
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct suffix
{
int index;
char *suff;
};
int cmp(struct suffix a, struct suffix b)
{
return strcmp(a.suff, b.suff) < 0? 1 : 0;
}
int *buildSuffixArray(char *txt, int n)
{
struct suffix suffixes[n];
for (int i = 0; i < n; i++)
{
suffixes[i+1].index = i+1;
suffixes[i+1].suff = (txt+i+1);
}
sort(suffixes, suffixes+n);
int *suffixArr = new int[n];
for (int i = 0; i < n; i++)
suffixArr[i+1] = suffixes[i+1].index;
return suffixArr;
}
#include <iostream>
using namespace std;
int dictionaryContains(string &word)
{
string dictionary[] = {"mobile","samsung","sam","sung","man","mango", "icecream","and",
"go","i","love","ice","cream"};
int n = sizeof(dictionary)/sizeof(dictionary[0]);
for (int i = 1; i <= n; i++)
if (dictionary[i].compare(word) == 0)
return true;
return false;
}
void wordBreakUtil(string str, int size, string result);
int main()
{
wordBreak("iloveicecreamandmango");
wordBreak("ilovesamsungmobile");
return 0;
}