Time spent here:

Tuesday, 22 March 2016

MAXIMUM SUM INCREASING SUB SEQUENCE(GEEKS FOR GEEKS)

Given an array of n positive integers. Write a program to find the sum of maximum sum subsequence of the given array such that the intgers in the subsequence are sorted in increasing order.
Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is N,N is the size of array.
The second line of each test case contains N input A[].

Output:
Print the sum of maximum sum sequence of the given array.

Constraints:
1 ≤ T ≤ 50
1 ≤ N ≤ 100
1 ≤ A[] ≤ 1000

Example:
Input:
2
7
1 101 2 3 100 4 5
4
10 5 4 3
Output:
106
10
CODE:
#include<stdio.h>


int maxSumIS( int arr[], int n )
{
    int i, j, max = 0;
    int msis[n];

   
    for ( i = 0; i < n; i++ )
        msis[i] = arr[i];

   
    for ( i = 1; i < n; i++ )
        for ( j = 0; j < i; j++ )
            if ( arr[i] > arr[j] && msis[i] < msis[j] + arr[i])
                msis[i] = msis[j] + arr[i];

    
    for ( i = 0; i < n; i++ )
        if ( max < msis[i] )
            max = msis[i];

    return max;
}

int main()
{
   int t,i;
   scanf("%d",&t);
   while(t--)
    {
    int n;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
     scanf("%d",&a[i]);
    printf("%d\n",maxSumIS( a, n ) );
    }
    return 0;
}

PROJECT-STUDENT SKILL SET TRACKER

ABSTRACT:

Student and Activity Tracker System (SATS) is an automated system SATS gives the facility to define the tasks in the organization and also allows the staff to track the student for that particular company. A report generation facility is supported in SATS that allows the staff to analyze which are those skills by student are utilized and those which are not utilized. This tool can help managers to take required student for the organisation.

PROJECT SCREENSHOTS:






Monday, 21 March 2016

FIND THE Nth TERM IN THE SERIES

Find the Nth term in d series that contains only 3 & 7
eg, 3,7,33,37,73,77,333,337,373,377,.....
Input Format
A single number N
where 0 < N < 100
Output Format
The number that is in d Nth position in d series.
Sample Input
3
Sample Output
33
Explanation
3,7,33,37,..
where 33 is d 3rd number in d series.
OUTOUT:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
 int x;
    scanf("%d",&x);
  int i;
    for(i=0;x>=pow(2,i);i++)
       x=x-pow(2,i);
    char s[i];
    s[i]='\0';
    for(i=i-1;i>=0;i--)
    {
        if(x%2==0)
            s[i]='3';
        else
            s[i]='7';
        if(x!=0)
            x=x>>1;
    }    
  printf("%s",s);
    return 0;
}

Wednesday, 16 March 2016

BREATH FIRST IMPLEMENTATION IN C

#include<stdio.h>
#include<conio.h>
int a[20][20],q[20],visited[20],n,i,j,f=0,r=-1;
void bfs(int v)
{
 for(i=1;i<=n;i++)
  if(a[v][i] && !visited[i])
   q[++r]=i;
 if(f<=r)
 {
  visited[q[f]]=1;
  bfs(q[f++]);
 }
}
void main()
{
 int v;
 clrscr();
 printf("\n Enter the number of vertices:");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
  q[i]=0;
  visited[i]=0;
 }
 printf("\n Enter graph data in matrix form:\n");
 for(i=1;i<=n;i++)
  for(j=1;j<=n;j++)
   scanf("%d",&a[i][j]);
 printf("\n Enter the starting vertex:");
 scanf("%d",&v);
 bfs(v);
 printf("\n The node which are reachable are:\n");
 for(i=1;i<=n;i++)
  if(visited[i])
   printf("%d\t",i);
  else
   printf("\n Bfs is not possible");
 getch();
}

SPECIAL KEYBOARD

Imagine you have a special keyboard with the following keys: 
Key 1:  Prints 'A' on screen
Key 2: (Ctrl-A): Select screen
Key 3: (Ctrl-C): Copy selection to buffer
Key 4: (Ctrl-V): Print buffer on screen appending it
                 after what has already been printed. 
If you can only press the keyboard for N times (with the above four keys), write a program to produce maximum numbers of A's. That is to say, the input parameter is N (No. of keys that you can press), the output is M (No. of As that you can produce).
Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is N,N is the number of key.

Output:
Print maximum number of A's.

Constraints:
1 ≤ T ≤ 50
1 ≤ N ≤ 75

Example:
Input:
2
3
7
Output:
3
9
Explanation:
Input:  N = 3
Output: 3
We can at most get 3 A's on screen by pressing 
following key sequence.
A, A, A
Input:  N = 7
Output: 9
We can at most get 9 A's on screen by pressing 
following key sequence.
A, A, A, Ctrl A, Ctrl C, Ctrl V, Ctrl V
OUTPUT:
#include <stdio.h>
int maxopt(int n)
{
    if(n <= 6)
     return n;
    int max=0,i;
    for(i=n-3;i>=1;i--)
    {
        int k=(n-i-1)*maxopt(i);
       
        if(k > max)
          max=k;
   
    }

    return max;
}
int main()
{
   int t,n;
   scanf("%d",&t);
   while(t--)
   {
       scanf("%d",&n);
       printf("%d\n",maxopt(n));
         
   }
    return 0;
}

Tuesday, 15 March 2016

SUM OF DIGIT AS PALINDROME(GEEKS FOR GEEKS )

Write a program to check if the sum of digits of a given number is pallindrome number or not.
Input:
The first line of the input contains T denoting the number of testcases.Then each of the T lines contains single positive integer N denoting the value of number.

Output:
Output "YES" if pallindrome else "NO". (without the quotes)

Constraints:
1<=T<=100
1<=N<=1000

Example:
Input:
2
56
98
Output:
YES
NO
SOURCE CODE:
#include <stdio.h>
int k;
int palindrome(int n)
{
    int a[100],count=0,i,j;
    i=0;
    while(n)
    {
        a[i]=n%10;
        n=n/10;
        count++;i++;
  }
if(count==1 || k==0)
    {
        return 1;
    }
j=count-1;
for(i=0;i<count;i++)
{
    if(a[i]!=a[j])
      return 0;
   j--;
 }
return 1;    
}
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
   scanf("%d",&n);
   int sum=0,count=0;k=n;
   while(n)
   {
       sum=sum+(n%10);
       n=n/10;
   }
   if(palindrome(sum))
   {
       printf("YES\n"); 
   }
   else
   {
       printf("NO\n");
   }
}
return 0;
}

SUM OF TWO NUMBER REPRESENTED AS ARRAY

Given two numbers represented by two arrays, write a function that returns sum array. The sum array is an array representation of addition of two input arrays. It is not allowed to modify the arrays.
Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case contains two integers M and N separated by a space. M is the size of arr1 and N is the size of arr2.
The second line of each test case contains M integers which is the input for arr1.
The third line of each test case contains N integers which is the input for arr2.

Output:
Print the sum list.

Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ M ≤ 1000
0 ≤ arr1[i],arr2[i]≤ 9

Example:
Input:
2
3 3
5 6 3
8 4 2
16 4
2 2 7 5 3 3 7 3 3 6 8 3 0 5 0 6 
4 3 3 8 
Output:
1 4 0 5

2 2 7 5 3 3 7 3 3 6 8 3 4 8 4 4
CODE:
#include <stdio.h>
int main() {
int t,i,j,count=0,n,m;
scanf("%d",&t);
while(t--)
{
    scanf("%d %d",&m,&n);
    int a[m],b[n];
    for(i=0;i<m;i++)
       scanf("%d",&a[i]);
    for(i=0;i<m;i++)
       scanf("%d",&b[i]);
    j=n-1;
    for(i=m-1;i>=m-n;i--)
    {
        int k=a[i]+b[j]+count;
       // printf("k=%d\n",k);
        if(k>=10)
        {
            a[i]=k%10;
            count=k/10;
        }
       else
       {
           a[i]=k;
           count=0;
       }
    
        j--;
    }
 if(count!=0)
  printf("%d ",count);
 for(i=0;i<m;i++)
       printf("%d ",a[i]);
printf("\n");    
}
return 0;
}

NEXT SPARSE BINARY NUMBER:(GEEKSFORGEEKS)

Given an integer n in the input, find its next sparse binary number.A sparse binary number is a number whose binary representation does not contain any consecutive 1s.
Input:
The first line of input contains an integer T denoting the number of test cases. The first line of each test case is number 'N'
Output:
Print next Sparse binary number,if the input number is not sparse else print the number itself.

Constraints:
1 ≤ T ≤ 100
1 ≤ n ≤ 100000
Example:
Input
2
3
5
Output
4
5
CODE:
#include <stdio.h>
int isSparse(int n)
{
   int k=n>>1;

    if(n & k)
      {return 0;}
    else
     { printf("%d\n",n);return n;}
}
int main() {
 int t,n,i; int k;
 scanf("%d",&t);
 for(i=0;i<t;i++)
 {
     scanf("%d",&n);
     while(1)
   {
      if (isSparse(n))
        {
          break;
        }
      else 
         n++;
   }
  
}
return 0;
}