Thursday, 22 May 2014

How to host your websites for FREE!!

Almost everyone who owns a computer also owns at least one website these days. Be it personal or professional. There are a number of hosting services available on the web for us to host our websites but most of them cost money. A simple and efficient way to host websites can be Google Drive. With its free storage space of up to 15 GB, you can host a fairly large website without any cost.

Google Drive can be used to host basic websites or even complex JavaScript-based web apps. You may publish any kind of static content on your website including HTML pages, images, CSS, icons, audio, video etc.

Note: However, Google Drive does not support web resources that make use of server-side scripting languages like PHP.

Here's how:

1)Create a public file folder.

2) Put your website i.e.the HTML, CSS, Javascript files inside it.

3)Open the HTML file and preview it.

4) Share the URL that looks like "www.googledrive.com/host/..." from the preview window.

To create a public folder: For this, you simply need to go to folders, create a new folder, and rename it to whatever name you want. Following which, you select the checkbox next to the New folder. Click the "Sharing settings" icon. Then click "Change" and make your folder "Public on the web".






To put files in the public folder: Click on your New folder’s title. The new folder is empty as of now. Click on “Upload Files" icon. Select the index.html or other files from you hardrive and then click on upload (Uploading via browser).

If you are using Google Drive on your desktop then simply move your folder into the Google Drive Folder.

NOTES:

a) If you're using any external files in your website, like a JavaScript library or a web font hosted elsewhere, link to the secure version of that file (if possible). By default, Google Drive sites redirect to HTTPS, and any insecure links may visitors ‘security warnings’ on the website.

b) If you do not start with an “index.html” file, then the site visitors will not see a website. Instead they will get a directory listing of all the folders in the website. So be sure to include it.



Opening and previewing HTML file: Click on the index.html page. Drive will open the file. Click on the "Open" button at the lower right corner of the screen.



Once you open the file select “Preview”.



Your live page should open. The URL in the address bar is your new site's URL.
Sharing the URL: Now that you have your URL, simply share with all you know!!

And Bammmm! Your website is live and running.

Note: If you wish to assign a custom domain to this site, note that Google Drive sadly doesn’t allow you to set the DNS values. But you can have an index page which contains a single iframe fetching content from this URL and set its width and height to 100%.

Saturday, 10 May 2014

Boyer-Moore String Matching

You are supposed to implement Boyer Moore algorithm using bad character rule as explained in the lecture.

Input:
First line contains the text T. Second line contains the pattern P

Output:
Index of each occurrence of pattern P in small brackets as shown in the examples below.

Constraints:
1 <= length(P) <= length(T) < 100

#include<limits.h>
#include<string.h>
#include<stdio.h>
#define CHAR_SET_SIZE 256
void process(char *str, char *ptr, int R[CHAR_SET_SIZE])
{
int i,j;
int m=strlen(str);
int n=strlen(ptr);
for(i = 0; i < CHAR_SET_SIZE; i++)
{
R[i] = -1;
}
for(i = 0; i < m; i++)
{
for(j=0;j<n;j++)
{
if(ptr[j]==str[i])
R[j]=i;
}
}
}
void patternMatcher(char *T, char *P)
{
int R[CHAR_SET_SIZE],n,m,i,l,temp,count=0;
n=strlen(P);
m=strlen(T);
char A[m];
process(T,P,R);
for(l=0;l<n;l++)
{
A[l]=P[l];
}
temp=n-1;
for(i=0;i<m;i++)
{
while((T[temp]==A[temp])&&(temp>i-1))
temp--;
if(temp==i-1)
{
printf("(%d)",i);
count++;
}
for(l=i+1;l<n+i+1;l++)
{
A[l]=P[l-i-1];
}
temp=n+i;
}
if(count==0)
printf("-1");
}
int main()
{
char P[100],T[100];
gets(T);
gets(P);
patternMatcher(T,P);
return 0;
}

Saturday, 3 May 2014

NovaPDF-The best PDF converter

novaPDF is a PDF printer for Windows that allows you to easily create 100% industry-standard PDF files.You can convert images as well as documents to pdf using novaPDF

It's never been easier to print to PDF, you simply open your document, click on "Print" and select novaPDF as the printer to generate the PDF. Try it now and see how easy it is to create PDFs: Download novaPDF.
novaPDF
You can use novaPDF to print to PDF from the first second after it's installed without configuring anything. However, even if it's very easy to create PDFs, it still contains a plethora of features:
  • Bookmarks are recognized and included in the resulting PDF
  • Your PDF can contain active PDF links (clickable)
  • Can be installed and used as a shared network PDF printer
  • You can watermark PDFs with text/images
  • Password protect the PDF or restrict copy/paste
  • Overlay and/or merge PDF files
  • Lots of other features as described in detail here: novaPDF Professional.
The best part about novaPDF is that you can use it for free before deciding to purchase a license. Wait no more, download novaPDF now to start printing to PDF.

Friday, 2 May 2014

Count pairs such that x^y > y^x

Given a sequence A of N positive integers, write a program to find the number of pairs (A[i], A[j]) such that i < j and A[i]A[j] > A[j]A[i] (A[i] raised to the power A[j] > A[j] raised to the power A[i]).
You are provided with a function named power( ) that takes two positive integers x & y and returns xy. If y is 0, the function returns 1.
The prototype of this function is
int power(int x, int y);
In your program, use this function to count the number of such pairs.

INPUT: Line 1 contains N.
Line 2 contains a sequence of N integers, separated by whitespace.

OUTPUT: A single integer representing the number of required pairs.

CONSTRAINTS: The inputs will satisfy the following properties. It is not necessary to validate the inputs.
1 <= N <= 30
0 <= A[i] <= 8 The input sequence can have repetitions and the count must reflect that.

#include<stdio.h>
int power(int x, int y);
int main()
{
int n,a[30],i,j,count=0;
scanf("%d",&n);
i=0;
while(i<n)
{
scanf("%d",&a[i]);
i++;
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(power(a[i],a[j])>power(a[j],a[i]))
count++;
}
}
printf("%d",count);
return 0;
}
int power(int x, int y)
{
int result = x;
if(y == 0)
return 1;
if(x < 0 || y < 0)
return 0;
for(int i = 1; i < y; ++i)
result *= x;
return result;
}

Evaluating a Polynomial

You are given a polynomial of degree n. The polynomial is of the form P(x) = anxn + an-1xn-1 + … + a0, where the ai‘s are the coefficients. Given an integer x, write a program that will evaluate P(x).

INPUT: Line 1 contains the integers n and x separated by whitespace.
Line 2 contains the coefficients an, an-1…, a0 separated by whitespace.

OUTPUT: A single integer which is P(x).

CONSTRAINTS: The inputs will satisfy the following properties. It is not necessary to validate the inputs.
1 <= n <= 10 1 <= x <= 10 0 <= ai <=10

#include<stdio.h>
int power(int x, int y);
int main()
{
int n,a[10],i,x,p=0;
scanf("%d%d",&n,&x);
i=n;
while(i>=0)
{
scanf("%d",&a[i]);
i--;
}
for(i=n;i>=0;i--)
{
p += a[i]*power(x,i);
}
printf("%d",p);
return 0;
}
int power(int x, int y)
{
int result = x;
if(y == 0)
return 1;
if(x < 0 || y < 0)
return 0;
for(int i = 1; i < y; ++i)
result *= x;
return result;
}

Evaluating a Recurrence Relation

A recurrence relation T is defined on n >= 0 and is given as T(n) = T(n-1) + 2*n with the base case T(0) = 1. You will be given one integer k and you have to write a program to find out T(k). The program must implement T( ) recursively.

INPUT:
One integer k.

OUTPUT:
T(k)

CONSTRAINTS:
The input k will satisfy the constraints 0 <= k <= 1000. You do not have to check if the input given to you falls outside this range.

#include<stdio.h>
int t(int x);
int main()
{
int x;
scanf("%d",&x);
printf("%d",t(x));
return 0;
}
int t(int x)
{
if(x==0)
return 1;
else
return (t(x-1) + 2*x);
}

Palindrome Checker

Write a program which takes a string as input and prints the longest prefix of the string whose reverse is a valid suffix of the string. For example, if "notation" is given as input, the prefix "no" is the longest prefix that has a matching valid suffix (namely "on") at the end.
If a string is a palindrome (i.e. if the string is the same as its reverse), then the prefix is the whole string itself. For example, if input is "civic", then the longest prefix is "civic" itself. If the string has no valid prefix, print 0. For example, if the input string is "bird", there is a mismatch at the first character itself and there is no valid prefix.
The symbols in the string will only be from the set {A-Z,a-z}. The symbols are case sensitive. i.e. ‘A’ and ‘a’ are considered to be different.
Use function : void printChars(char *p, char *q);

INPUT:
Input is a string of length N composed of symbols only from the set {A-Za,z}.

OUTPUT:
The longest prefix that has a corresponding matching suffix and 0 if such a prefix does not exist.

CONSTRAINTS:
The inputs will satisfy the following properties. It is not necessary to validate the inputs.
1<=N<=99

#include<stdio.h>
#include<string.h>
void printChars(char *p,char *q);//function prototype
int main()
{
char a[100],*p,*q;
int x=0,y,i=0,f=0;
scanf("%s",a);
for(i=0;i<strlen(a);i++)
{
y=a[i];
if( (y<65) || ( y>90 && y<97) || (y>122) )
x++;
}
i=0;
if((a[0]==a[strlen(a)-1]) && (x==0))
{
 p=&a[0];
while((a[i]==a[strlen(a)-i-1])&&(f<strlen(a)))
{
q=&a[i];
i++;
f++;
}
}
else
p=NULL;
printChars(p,q);
return 0;
}
void printChars(char *p, char *q)
{
if (p==NULL)
{
printf("0");
}
else
{
while(p <= q)
{
printf("%c",*p);
p++;
}
}
}

Merging words

You are given two words (not necessarily meaningful words) over the lower case English alphabet. They are to be merged into a single new word in which all the letters (including repetitions) in the given two words occur in increasing order (‘a’ is the least and ‘z’ is the largest) from left to right.
Example : If the two words are “ehllo” and “wrold”, the output is “dehllloorw”.
Explanation : d, e, h , l, o, r, w is the increasing order among the distinct letters. Since all the letters must occur in the output word, the output is “dehllloorw”.

Input : Two words, one on each line.

Output : The merged word as described in the problem statement.

Constraints : 0 < length of each word <= 10.

#include<stdio.h>
#include<string.h>
int main()
{
char s1[20],s2[10],a;
int c,i,j,x[26]={0};
scanf("%s %s", s1,s2);
strcat(s1,s2);
for(i=0;i<26;i++)
{
c=s1[i];
c=c-97;
x[c]++;
}
for(i=0;i<26;i++)
{
while(x[i]>0)
{
j=i+97;
a=j;
printf("%c",a);
x[i]--;
}
}
return 0;
}

Sorting words

You are given a set of words over the lowercase English alphabet. They are to be sorted in alphabetical order.
Alphabetical order : It is the order in which words are organized in a dictionary or in an telephone directory.
For example,
abc comes before xab. Reason : The first letters differ. So, they are compared. a comes before x in English alphabet.
aab comes before abc. Reason : The first letters are same (aab abc). So, the next 2 letters are compared (aab abc).
aab comes before aaba. Reason : The first 3 letters in aab are same as the first 3 letters in aaba and there are no more letters in aab to compare against aaba. So, the word with the smaller length comes first (aab).

Input - The first line has ‘n’, the number of words, followed by n lines each of which contains a word.

Output - Words in alphabetical order, one one each line.

Constraints : 0 < n <=100, 0 < length of each word <= 10

#include <stdio.h>
#include <string.h>
int main()
{
int num, i, j, result, index;
char name[100][11];
char temp[11];
scanf("%d", &num);
for(i = 0; i < num; i++)
scanf("%s", name[i]);
for(i = 0; i < num; i++)
{
index = i;
for(j = i + 1; j < num; j++)
{
result = strcmp(name[index], name[j]);
if(result > 0)
index = j;
}
strcpy(temp, name[index]);
strcpy(name[index], name[i]);
strcpy(name[i], temp);
}
for(i = 0; i < num-1; i++)
{
printf("%s\n", name[i]);
}
printf("%s", name[i]);
return 0;
}

Multiply Polynomials

A polynomial of degree n is of the form P(x) = anxn + an-1xn-1 + … + a0. Given two polynomials f(x) and g(x) of degrees n and m respectively, write a program to find the polynomial h(x) given by,
h(x) = f(x) * g(x)

INPUT: Line 1 contains n and m separated by space.
Line 2 contains the coefficients an, an-1…, a0 of f(x) separated by space.
Line 3 contains the coefficients bm, bm-1…, b0 of g(x) separated by space.
OUTPUT: The degree of h(x) followed by the coefficients ck, ck-1…, c0 of h(x) in next line separated by space.
Constraints:
1 <= n <= 10
1 <= ai <= 100

#include<stdio.h>
#include<string.h>
int main()
{
int n,m,i,j,x,a[10],b[10],c[10][10],d[20]={0};
scanf("%d %d",&n,&m);
for(i=n;i>=0;i--)
scanf("%d",&a[i]);
for(i=m;i>=0;i--)
scanf("%d",&b[i]);
for(i=n;i>=0;i--)
{
for(j=m;j>=0;j--)
{
c[i][j]=a[i]*b[j];
}
}
for(x=0;x<=m+n;x++)
{
for(i=0;i<=n;i++)
{
for(j=0;j<=m;j++)
{
if(i+j==x)
{
d[x] += c[i][j];
}
}
}
}
printf("%d\n%d",m+n,d[m+n]);
for(x=m+n-1;x>=0;x--)
{
printf(" %d",d[x]);
}
return 0;
}

Horner's Rule

You are given a polynomial of degree n. The polynomial is of the form P(x) = anxn + an-1xn-1 + … + a0. For given values k and m, You are required to find P(k) at the end of the mth iteration of Horner’s rule. The steps involved in the Horner’s rule are given below,

P(x) = an
Pn-1 (x) = an-1 + x * P(x)                          1st iteration.
Pn-2 (x) = an-2 + x * Pn-1 (x)                        2nd iteration.
.
.
P(x) = a0 + x * P(x)                             nth iteration.

In general, P(x) = ai + x * Pi + 1 (x) and P0(x) is the final result. The input to your program is as follows,

Line 1 contains the integers n, m and k separated by space.
Line 2 contains the coefficients an, an-1…, a0 separated by space.

INPUT: Integers n, m, k and the coefficients as described above.

OUTPUT: P(k) value at the end of the mth iteration.

Constraints:
1 <= n, k, m <= 10
0 <= a<=10




#include<stdio.h>
#include<math.h>
int function(int,int);
int c[10],i=0,n,m;
int main()
{
    int k;
    scanf("%d %d %d",&n,&m,&k);
    for(i=n;i>=0;i--)
     scanf("%d",&c[i]);
	i=n;
    printf("%d",function(m,k));
	return 0;
}
int function( int m, int k)
{
	int j;
	if(m==0)
	{
	 return(c[n]);
	}
	else
	{
	 j=n-m;
	 return( c[j] + k*function(m-1,k) );
    }
}

Implementing a Hash Table ADT

A hash table is a data structure that maps a set of keys to a given set of values. It uses a hash function to compute an index into an array of buckets or slots, from which the correct value can be found or to which a correct value can be inserted. A hash function will assign each key to a unique bucket or slot. In practice, however, there may be more than one key that will hash to the same bucket. Such an assignment is said to result in a collision.

In this assignment, you have to implement a Hash Table ADT using arrays and linked lists. The algorithm should accommodate the features described below:

  1. Your program should take as input 10 non-negative integers as key values and insert them to a hash table.
  2. The hash table has to be implemented using the hash function h(x) = x%10, where x is the input value.
  3. Input values that return the same value for h(x) have to be properly accommodated such that if there is a collision, the index from the array to the appropriate bucket should point to a linked list that can take in all the values that hash to the same bucket. i.e., you can have an array of linked lists such that each entry of the array is a pointer to a bucket. For e.g., when h(x) returns 4, the input value should go into the linked list starting from A[4].
  4. Your program should report when there is a collision and must specify the position (starting at 1 for the 1st element) in the input list of that key value where the collision occurred. It should also report the bucket number and the number of entries in each bucket
  5. If there are no collisions, the program should report ‘NO’.
  6. HashTable class has a printCollision function which you cannot re-write. The string you want to print has to be made available in the private data variable “collision” using listCollision function in class HashTable.

INPUT:
A list of 10 non-negative integers with a single space between the entries.

OUTPUT:
3-tuple indicating the position in the input list where the collision occurred, the corresponding bucket number and the number of elements in that bucket, each 3-tuple has to be separated by a single space.

CONSTRAINTS:
0 <= key <1000



#include <iostream>
#include <stdlib.h>
#include <string>
#include <sstream>
using namespace std;
typedef struct CellType* Position;
typedef int ElementType;
struct CellType{
    ElementType value;
    Position next;
};
class List{
    private:
        Position listHead;
        int count;
    public:
        //Initializes the number of nodes in the list
        void setCount(int num){
            count = num;
        }
        //Creates an empty list
        void makeEmptyList(){
            listHead = new CellType;
            listHead->next = NULL;
        }        
        //Inserts an element after Position p
        int insertList(ElementType data, Position p){
            Position temp;
            temp = p->next;
            p->next = new CellType;
            p->next->next = temp;
            p->next->value = data;    
            return ++count;            
        }        
        //Returns pointer to the last node
        Position end(){
            Position p;
            p = listHead;
            while (p->next != NULL){
                p = p->next;
            }
            return p;            
        }
        //Returns number of elements in the list
        int getCount(){
            return count;
        }
};
class HashTable
{
    private:
        List bucket[10];
        int bucketIndex,x;
        int numElemBucket;
        Position posInsert;
        string collision;
        bool reportCol; //Helps to print a NO for no collisions
    public:
        HashTable()    //constructor
		{
            int i;
            for (i=0;i<10;i++)
            {
                bucket[i].setCount(0);
                bucket[i].makeEmptyList();
			}
			collision = "";
            x=0;
            reportCol = false;
        }
        void insert(int data)
		{
			bucketIndex = (data%10);
			posInsert = bucket[bucketIndex].end();
			bucket[bucketIndex].insertList(data,posInsert);
			listCollision(++x);
        }
        void listCollision(int pos)
		{       
			numElemBucket = bucket[bucketIndex].getCount();
			if(numElemBucket>1)
			{
			 collision = collision + '(';
			 if(pos+48==58)
			  {
			   collision += 49;
			   collision += 48;
			  }
			 else
			 {  
			  collision += pos+48;
			 }
			 collision += ',';
			 collision += bucketIndex+48;
			 collision += ',';
			 if(numElemBucket+48==58)
			  {
			   collision += 49;
			   collision += 48;
			  }
			 else
			 {  
			  collision += numElemBucket+48;
			 }
			 collision += ')';
			 collision += ' ';
		     reportCol = true;
			}
		}
           void printCollision();
};
void HashTable::printCollision()
{
    if (reportCol == false)
        cout <<"NO";
    else
        cout<<collision;
}
int main()
{    
    HashTable ht;
    int i, data;   
	for (i=0;i<10;i++)
	{
        cin>>data;
        ht.insert(data);
        }
//Prints the concatenated collision list
   ht.printCollision(); 
}

Big Int Addition

Primitive int data type handles integers each of which can be stored using 32 bits. Similarly long data type also has a limit. In this assignment you have to implement a data type which handles numbers larger than int , long and long long.


You are given a number in decimal form. You need to build a data structure called BigInt which can store that data, and perform the following basic operations on that data type:

   1.BigInt::add(BigInt A ), returns the result in another BigInt, without altering the numerical value of the caller.
   2.BigInt::print(), this function must print Most significant digit at the beginning and must not print any leading zeroes.
      Ex:     123 (correct )
              0123 (incorrect)
   3.populate(BigInt &A, char * str), populates the List in BigInt using public methods of BigInt.

Note that populate(BigInt &A, char * str) method is not a function of BigInt.



Input:
Input will have two lines, each line contains a single BigInt.


Output:
Output contains the result of the addition in a single line.
Output of the above sample input is as follows.


Constraints:
1 ≤ Input length of BigInt ≤ 40 digits.
Input for BigInt is always positive



#include <iostream>
#include <cstring>
using namespace std;
class ListNode{
 private:
  int data;
  ListNode * next;
 public:
  ListNode(){}
  ListNode(int num){
   data=num;
   next = NULL;
  }
  int getData();
  void setData(int);
  void setNext(ListNode *);
  ListNode* getNext();
};
int ListNode::getData(){
  return data;
}
void ListNode::setData(int x){
  data = x;
}
ListNode * ListNode::getNext(){
  return next;
}
void ListNode::setNext(ListNode * P){
  next = P;
}
class List{
 private:
  ListNode * Head;
 public:  
  List(){
   Head=NULL;
  }
  ~List(){}
  ListNode * getHead();
  void setHead(ListNode *);
  ListNode * last();
  void append(int);
  void prepend(int);
  void popBack();
  void print();
  void copy(List);
  void printReverse();
  ListNode * prevNode(ListNode* P);
  void popFront();      
};
ListNode * List::getHead(){
  return Head;
}
ListNode * List::last(){
  ListNode * temp=Head;
  if(Head==NULL) return NULL;
  while(temp->getNext()!=NULL){
   temp=temp->getNext();
  }
  return temp;
}
void List::setHead(ListNode * P){
  Head = P;
}
void List::append(int num){
  ListNode * new_node = new ListNode(num);
  ListNode * temp=Head;
  if(temp==NULL){
   Head = new_node;
   return;
  }
  while(temp->getNext()!=NULL) temp=temp->getNext();
  temp->setNext(new_node);
}
void List::prepend(int num){
  ListNode * new_node = new ListNode(num);
  new_node->setNext(Head);
  Head = new_node;
}
void List::popBack(){
  ListNode * temp=Head,*prev=NULL;
  //NULL list
  if(Head==NULL){cout<<"List is Empty\n";}
  //single element
  if(Head->getNext()==NULL){
   delete Head;
   Head=NULL;
   return;
  }
  while(temp->getNext()!=NULL){
   prev = temp;
   temp=temp->getNext();
  }
  delete temp;
  prev->setNext(NULL);
}
void List::print(){
  ListNode * temp=Head;
  while(temp!=NULL){
   cout<<temp->getData();
   temp=temp->getNext();
  }
}
void List::copy(List L){
  Head = NULL;
  ListNode * temp = L.Head;
  while(temp!=NULL){
   this->append(temp->getData());
   temp=temp->getNext();
  }
}
void List::printReverse(){
  ListNode * curr=Head;
  ListNode * prev_last=NULL;
  while(Head!=NULL && prev_last!=Head){
   curr = Head;    
   while(curr->getNext()!=prev_last){
    curr = curr->getNext();
   }
   cout<<curr->getData();
   prev_last = curr;
  }
}
class BigInt{
   private: 
     List L;
   public:
    BigInt(){}
    ~BigInt(){}
    void append(int num);
    void prepend(int num);
    BigInt add(BigInt A);
    void print();
    void removeZeroes();
    void copy(BigInt B);

};
List L1,L2,L3;
int y=0;
void populate(BigInt &A, char * str){
 int i,c=0,x=0,j,l=strlen(str);
  for(i=0;i<l;i++)
  {
   c=str[i];
   if( (c==48) && (x==0) )
    {
     for(j=0;j<l;j++)
      str[j]=str[j+1];
    }
   else
    x++; 
  } 
  for(i=strlen(str)-1;i>=0;i--)
  { 
     c=str[i];
    if(y==0)
  L1.append(c-48);
    if(y==1)
  L2.append(c-48);
  }
  y++;
}
BigInt BigInt::add(BigInt A)
{
      int a,b,m,n=0;
  ListNode * temp1=L1.getHead(), * temp2=L2.getHead();
  while(temp1!=NULL || temp2!=NULL)
 {
   if(temp1!=NULL)
   {
    a=temp1->getData();
   }
   else
    a=0;
   if(temp2!=NULL)
   {
    b=temp2->getData();
   }
   else
    b=0;
   m=(n+a+b)%10;
   n=(n+a+b)/10;
   L3.append(m);
   if(temp1!=NULL)
    temp1=temp1->getNext();
   if(temp2!=NULL)
    temp2=temp2->getNext();
 }
if(temp1==NULL && temp2==NULL && n!=0)
  L3.append(n);
 return A;
}
void BigInt::print()
{
    L3.printReverse();
}
int main(){
      char str[40];
      BigInt A,B;
      cin>>str;
      populate(A,str);
      cin>>str;
      populate(B,str);
      (A.add(B)).print();
      return 0;
}