Monday, September 3, 2012

Aspiration 2020 Solutions and Problems in c c++ and java


RSA Encryption
============


#include"stdio.h"
int pow(int x,int y)
{ int ans=1;
for(int i=1;i<=y;i++)
{
ans=ans*x;
}
return ans;
}
int getCipher(int plainText)
{ if(plainText<0)
return -1;
return (((pow(plainText,3)%33)*(pow(plainText,3)%33)*(plainText%33))%33);
}
int main()
{
//Test case 1:
{
int plaintext = 13;
int cipherText = getCipher(plaintext);
printf("plain text = %d \n",cipherText);
}
//Test case 2:
{
int plaintext = 14;
int cipherText = getCipher(plaintext);
printf("plain text = %d \n",cipherText);
}
//Test case 3:
{
int plaintext = 27;
int cipherText = getCipher(plaintext);
printf("plain text = %d \n",cipherText);
}
}



RSA Decryption
--------------------

#include"stdio.h"
int pow(int x,int y)
{ int ans=1;
for(int i=1;i<=y;i++)
{
ans=ans*x;
}
return ans;
}
int getPlain(int cipherText)
{ if(cipherText<0)
return -1;
return (pow(cipherText,3)%33);
}
int main()
{
//Test case 1:
{
int cipherText = 7;
int plaintext = getPlain(cipherText);
printf("plain text = %d",plaintext);
}
//Test case 2:
{
int cipherText = 152;
int plaintext = getPlain(cipherText);
printf("plain text = %d",plaintext);
}
//Test case 3:
{
int cipherText = 307;
int plaintext = getPlain(cipherText);
printf("plain text = %d",plaintext);
}
}


CGPA
========


#include"stdio.h"
float calcCGPA(float sgpa[],int credits[],int noOfSem)
{
int i=0;
while(i
{ if(sgpa[i]<0.0||credits[i]<=0)
return -1;
i++;
}
i=0; float sum=0,sum1=0;
while(i
{
sum=sum + sgpa[i]*credits[i];
sum1+=credits[i];
i++;
}
return (sum/sum1);
}

int main()
{
//TestCase 1
{
float sgpa[] = {0.8, 0.7, 0.6, 0.5};
int credites[] = {50, 100, 50, 100};
int noOfSem = 4;

float cgpa = calcCGPA(sgpa, credites, noOfSem);
printf("%f\n", cgpa);
}

//TestCase 2
{
float sgpa[] = {7.2, 8.32, 7.5};
int credites[] = {50, 100, 50};
int noOfSem = 3;

float cgpa = calcCGPA(sgpa, credites, noOfSem);
printf("%f\n", cgpa);
}

//TestCase 3
{
float sgpa[] = {7.2, 8.32, 7.5};
int credites[] = {50, 100, 0};
int noOfSem = 3;

float cgpa = calcCGPA(sgpa, credites, noOfSem);
printf("%f\n", cgpa);
}
}


Body Mass Index
============


#include"stdio.h"

char* getCategory(float height,float weight)
{
if(height <= 0 || weight <= 0 )
return "invalid";
double ht=height/100;
double bmiValue;
bmiValue = weight / (ht*ht);
if(bmiValue<15)
return "starvation";
else if(bmiValue >=15 && bmiValue <>
return "underweight";
else if( bmiValue >=18.5 && bmiValue <>
return "normal";
else if(bmiValue >= 25 && bmiValue <30)
return "overweight";
else if(bmiValue >=30 && bmiValue <>
return "obese";
else if(bmiValue >=40)
return "morbidly obese";
return "";
}

int main() {
//TestCase 1
{
float height = 200;
float weight = 67.8;
char* catagory = getCategory(height,weight);
printf ("\n%s",catagory);
}

//TestCase 2
{
float height = 168;
float weight = 70.2;
char* catagory = getCategory(height,weight);
printf ("\n%s",catagory);
}

//TestCase 3
{
float height = 0.0;
float weight = 70.2;
char* catagory = getCategory(height,weight);
printf ("\n%s",catagory);
}
}


Practical Number
=============


#include
#include
int find_diviser(int x[],int num)
{
int i=2,k=0;
x[k++]=1;
while(i<=num/2)
{ if(num%i==0)
x[k++]=i;
i++;
}
return k;
}
int check(int nondivisor,int divisors[],int size)
{
int result[2000]={0};
int difference,largest=divisors[0];
int i,j=0,k,l,m,n;
int sum=0;
for(i=size-1;i>=0;i--)
{

largest=divisors[0];
for(k=0;k
{
sum=sum+result[k];
}

difference=nondivisor-sum;


for(l=i;l>=0;l--)
{
if(divisors[l]==difference)
{
result[j]=difference;
j++;
return 1;
}
else if((largest
{
largest=divisors[l];
i=l;
}
}
result[j]=largest;
j++;
sum=0;
}
return 0;
}
int check(int num)
{
int x[2000]={0},i;
int n=find_diviser(x,num);
if(num==1)
return 1;
if(num%2!=0)
return 0;
for(i=2;i
{ if(!check(i,x,n))
{return 0;}
}
return 1;
}
int getNoOfPracticalNumbers(int from ,int to)
{
if(from<=0||to<=0||(to-from)>=10000)
return -1;
int i=0;
while(from<=to)
{
if(check(from)==1)
i++;
from++;
}
return i;
}
int * getPracticalNumbers(int from,int to)
{ if(from<=0||to<=0||(from-to)>=10000)
return NULL;
int * ans=(int *)malloc(sizeof(int)*getNoOfPracticalNumbers(from,to));
int i=0;
while(from<=to)
{
if(check(from)==1)
ans[i++]=from;
from++;
}
return ans;
}
int main()
{
//Testcase 1:
{
int from = 1;
int to = 20;

int no = getNoOfPracticalNumbers(from, to);
int* output = getPracticalNumbers(from, to);

printf("\ngetNoOfPracticalNumbers : %d",no);
printf("\ngetPracticalNumbers : ");

if(output != NULL)
{
for(int i=0;i
printf ("%d, ",output[i]);
}
else
printf("%s",output);
}

//Testcase 2:
{
int from = 8000;
int to = 8200;

int no = getNoOfPracticalNumbers(from, to);
int* output = getPracticalNumbers(from, to);

printf("\n\ngetNoOfPracticalNumbers : %d",no);
printf("\ngetPracticalNumbers : ");

if(output != NULL)
{
for(int i=0;i
printf ("%d, ",output[i]);
}
else
printf("%s",output);
}

//Testcase 3:
{
int from = 1;
int to = 50;
int no = getNoOfPracticalNumbers(from, to);
int* output = getPracticalNumbers(from, to);

printf("\n\ngetNoOfPracticalNumbers : %d",no);
printf("\ngetPracticalNumbers : ");

if(output != NULL)
{
for(int i=0;i
printf ("%d, ",output[i]);
}
else
printf("%s",output);
}
}



Least Remaining Time
=================


#include"stdio.h"
#include"leastremainingtime.h"
#include"math.h"
#include"malloc.h"
struct IntArray getSchedule(int browsingTime[],int noOfPerson,int timeSlot)
{
int *s,*ss;
int i,j,k,l;
struct IntArray x;
x.nSize=0;
s=(int*)malloc(sizeof(int)*noOfPerson);
ss=(int*)malloc(sizeof(int)*noOfPerson);
for(i=0;i
{
s[i]=i+1;
}
for(i=0;i
{
for(j=0;j
{
if(browsingTime[j]>browsingTime[j+1])
{
k=browsingTime[j];
browsingTime[j]=browsingTime[j+1];
browsingTime[j+1]=k;
l=s[j];
s[j]=s[j+1];
s[j+1]=l;
}
}
}
for(i=0;i
{
ss[i]=browsingTime[i];
}



l=0;
for(i=0;browsingTime[noOfPerson-1]>0;i++)
{
for(j=0;j
{
if(browsingTime[j]>0)
{
browsingTime[j]=browsingTime[j]-timeSlot;
x.nSize=x.nSize+1;
}
}
}
x.schedule=(int*)malloc(sizeof(int)*x.nSize);
l=0;
for(i=0;ss[noOfPerson-1]>0;i++)
{
for(j=0;j
{
if(ss[j]>0)
{
ss[j]=ss[j]-timeSlot;
x.schedule[l]=s[j];
l++;
}
}
}


free (s);
return x;
}


int main()
{
//Testcase 1:
{
int browsingtime[] = {10,7,3,4,11};
int size = 5;
int time_slot = 5;
struct IntArray res = getSchedule(browsingtime, size, time_slot);
if(res.schedule != NULL)
for(int i=0;i
printf ("%d, ",res.schedule[i]);
printf("\n");
}

//Testcase 2:
{
int browsingtime[] = {3,7,14,4,11};
int size = 5;
int time_slot = 7;
struct IntArray res = getSchedule(browsingtime, size, time_slot);
if(res.schedule != NULL)
for(int i=0;i
printf ("%d, ",res.schedule[i]);
printf("\n");
}

//Testcase 3:
{
int browsingtime[] = {4,2,5};
int size = 3;
int time_slot = 1;
struct IntArray res = getSchedule(browsingtime, size, time_slot);
if(res.schedule != NULL)
for(int i=0;i
printf ("%d, ",res.schedule[i]);
}
return 0;
}



Chocolate Chips
===============


#include"stdio.h"
#include"Chocolate.h"
int check(double x,double y,double h,double k)
{ double d=(x-h)*(x-h)+(y-k)*(y-k);
if(d<=6.25)
return 1;
return 0;
}
int ChocolateChip(double x[],double y[],int noOfCoordinates)
{ int i,j,k;
int arr[10][10]={0};
if(noOfCoordinates<=0||noOfCoordinates>200)
return -1;
for(i=0;i
if(x[i]<=0||x[i]>50||y[i]<=0||y[i]>50)
return -1;
for(i=0;i
{ j=(int)x[i]/5;
k=(int)y[i]/5;
if(check(x[i],y[i],j*5+2.5,k*5+2.5))
arr[k][j]++;
}
int max=0,m;
for(i=0;i<10;i++)
for(m=0;m<10;m++)
if(max
max=arr[i][m];
return max;
}

int main()
{
// TEST CASE - 1
{
double x[5], y[5];
int i,j,k,m,mm,max = 0;
int noOfCoordinates = 5;
x[0] = 1.0, y[0] = 1.0;
x[1] = 2.3, y[1] = 2.1;
x[2] = 2.8, y[2] = 3.0;
x[3] = 5.5, y[3] = 6.1;
x[4] = 7.0, y[4] = 8.9;
int chips = ChocolateChip(x, y, noOfCoordinates);
printf ("\n\n Chips : %d",chips);
}
// TEST CASE - 2
{
double x[10], y[10];
int i,j,k,m,mm,max = 0;
int noOfCoordinates = 10;
x[0] = 1.0, y[0] = 1.0;
x[1] = 3.2, y[1] = 2.0;
x[2] = 4.5, y[2] = 3.0;
x[3] = 11.0, y[3] = 2.0;
x[4] = 1.4, y[4] = 2.5;
x[5] = 4.4, y[5] = 4.5;
x[6] = 2.8, y[6] = 3.5;
x[7] = 1.8, y[7] = 2.5;
x[8] = 13.4, y[8] = 4.5;
x[9] = 14.4, y[9] = 3.5;
int chips = ChocolateChip(x, y, noOfCoordinates);
printf ("\n\n Chips : %d",chips);
}
// TEST CASE - 3
{
double x[7], y[7];
int i,j,k,m,mm,max = 0;
int noOfCoordinates = 7;
x[0] = 1.1, y[0] = 1.7;
x[1] = 2.3, y[1] = 2.1;
x[2] = 3.8, y[2] = 4.5;
x[3] = 4.3, y[3] = 5.2;
x[4] = 2.8, y[4] = 3.0;
x[5] = 5.5, y[5] = 6.1;
x[6] = 7.0, y[6] = 8.9;
int chips = ChocolateChip(x, y, noOfCoordinates);
printf ("\n\n Chips : %d",chips);
}

}



Blur Image
============


#include"stdio.h"
#include"malloc.h"
#include"blurimage.h"

int r(int pixel)
{
int red;
red=pixel/256/256;
return(red);
}
int g( int pixel)
{
int green;
green=pixel/256%256;
return(green);
}
int b(int pixel)
{
int blue;
blue=pixel%256;
return(blue);

}

int formation( int sumr, int sumg, int sumb)
{
int rgb=(sumr*256*256)+(sumg*256)+sumb;
return(rgb);
}
int fun(int x,int radius,int y,int row,int col,int** acess)
{ int arrx1[100],count1=0,arry1[100],loc,flag=0,value;
int i,j,arrx[100],count=0,arry[100],l,avgr,avgg,avgb,sumr=0,sumg=0,sumb=0,red,green,blue,pixel,rgb;
int avg,sum=0,legal=0;
// acess=(int **)malloc(row*sizeof(int *));
for(i=1;i<=radius;i++)
{
for(j=1;j<=radius;j++)
{

arry[count+0]=y;
arrx[count+0]=x+i;
arry[count+1]=y;
arrx[count+1]=x-i;
arry[count+2]=y-j;
arrx[count+2]=x;
arry[count+3]=y+j;
arrx[count+3]=x;
arry[count+4]=y-j;
arrx[count+4]=x+i;
arry[count+5]=y+j;
arrx[count+5]=x+i;
arry[count+6]=y-j;
arrx[count+6]=x-i;
arry[count+7]=y+j;
arrx[count+7]=x-i;
count+=8;
}
}
for(j=0;j
{ loc=j;
for(i=0+j;i<8+j;i++)
{
for(l=loc;l>0;l-=8)
{

if((arrx[i]==arrx[i-l])&&(arry[i]==arry[i-l]))
{
flag=1;


}

}
if(flag==1)
{
flag=0;
continue;
}
arrx1[count1]=arrx[i];
arry1[count1]=arry[i];
count1++;


}
}
arrx1[count1]=x;
arry1[count1]=y;

for(value=0;value<=count1;value++)
{

if(arrx1[value]<0||arry1[value]<0||arrx1[value]>col||arry1[value]>row)
{

continue;
}

pixel=acess[arrx1[value]][arry1[value]];
red=r(pixel) ;
//printf("r=%x\n",red);
green=g(pixel);
blue=b(pixel);
sumr=sumr+red;

sumg=sumg+green;

sumb=sumb+blue;

legal++;

}
avgr=sumr/legal;
avgg=sumg/legal;
avgb=sumb/legal;
rgb=formation(avgr,avgg,avgb);
return rgb;
}struct image img,img1;
struct image * blur_image(struct image * i, int radius)
{
int row,col,i1,j;
if(radius>i->rows||radius>i->columns)
return NULL;
for(i1=0;i1rows;i1++)
for(j=0;jcolumns;j++)
if(i->data[i1][j]>0xffffff)
return NULL;
int r=i->rows;
int c=i->columns;
row=c-1,col=r-1;
img.rows=i->rows;
img.columns=col;
img.data = (int **) malloc((img.rows)*sizeof(int *));
for(int j=0; j<>
img.data[j] = &(i->data[j][0]);
int data1[1000][1000]={0};
for(i1=0;i1<=col;i1++)
{
for(j=0;j<=row;j++)
{
data1[i1][j]=fun(i1,radius,j,row,col,i->data);
//printf("%d",img.data[i1][j]);
}
//printf("\n");
}
for(i1=0;i1<=col;i1++)
{
for(j=0;j<=row;j++)
{
img.data[i1][j]=data1[i1][j];
//printf("%d",img.data[i1][j]);
}
//printf("\n");
}
return (&img);
}


int main()
{
//TestCase 1
{
printf("\nTestCase 1");

int data[5][3]= { {6,12,18}, {5,11,17}, {4,10,16}, {3,9,15}, {2,8,14} };
struct image i;
i.rows = 5;
i.columns = 3;

i.data = (int **) malloc((i.rows)*sizeof(int *));
for(int j=0; j<>
i.data[j] = &data[j][0];

struct image * res;
res = blur_image(&i,2);


if(res != NULL)
for(int k=0;k<5;k++)
{
printf ("\n");
for(int j=0;j<3;j++)
{
printf ("0x%x,\t", res->data[k][j]);
}
}
}

//TestCase 2
{
printf("\nTestCase 2");

int data[3][5]= {{ 0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038 },
{ 0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038 },
{ 0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038 } };
struct image i;
i.rows = 3;
i.columns = 5;

i.data = (int **) malloc((i.rows)*sizeof(int *));
for(int j=0; j<>
i.data[j] = &data[j][0];

struct image * res;
res = blur_image(&i,1);

if(res != NULL)
for(int k=0;k<3;k++)
{
printf ("\n");
for(int j=0;j<5;j++)
{
printf ("0x%x,\t", res->data[k][j]);
}
}
}
//TestCase 3
{
printf("\nTestCase 3");

int data[3][5]= {{ 0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038 },
{ 0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038 },
{ 0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038 } };
struct image i;
i.rows = 3;
i.columns = 5;

i.data = (int **) malloc((i.rows)*sizeof(int *));
for(int j=0; j<>
i.data[j] = &data[j][0];

struct image * res;
res = blur_image(&i,4);

if(res != NULL)
{
for(int k=0;k<3;k++)
{
printf ("\n");
for(int j=0;j<5;j++)
{
printf ("0x%x,\t", res->data[k][j]);
}
}
}
else
printf("NULL");
}

}

amicable Number
=============


#include"stdio.h"
#include"amicablenumber.h"
#include"malloc.h"
int find_diviser(int x[],int num)
{
int i=2,k=0;
x[k++]=1;
while(i<=num/2)
{ if(num%i==0)
x[k++]=i;
i++;
}
return k;
}
int check(int start)
{ int i,num,x[100],sum=0,sum1=0;
num=find_diviser(x,start);
for(i=0;i
sum+=x[i];
num=find_diviser(x,sum);
for(i=0;i
sum1+=x[i];
if(sum1==start&&sum!=sum1)
return sum;
return 0;
}
int chk(int num,struct amicable *var)
{ int i;
for(i=0;isize;i++)
{
if(num==var->amicablePair[i][1])
return 0;
}
return 1;
}
int chhk(int num,int arr[][100],int size)
{ int i;
for(i=0;i
{
if(num==arr[i][1])
return 0;
}
return 1;
}

int count(int startnum,int endnum)
{int arr[100][100];int ss=0,k=0;
for(int i=startnum;i<=endnum;i++)
{
if(check(i)&&chhk(i,arr,ss))
{
arr[k][0]=i;
arr[k++][1]=check(i);
ss++;
}
}
return k;
}
struct amicable var;
struct amicable *getAmicablePairs(int startnum, int endnum)
{ int rows=count(startnum,endnum);
if(startnum<=0||endnum>=15000||startnum>endnum||(endnum-startnum>=15000)||rows==0)
{
return NULL;}
var.size=rows;
var.amicablePair = (int **) malloc((var.size)*sizeof(int *));
int i,j;
int data[100][2]={0};
for(i=0;i
var.amicablePair[i]=&data[i][0];
printf("%d",var.size);
int k=0;
for(i=startnum;i<=endnum;i++)
{
if(check(i)&&chk(i,&var))
{
var.amicablePair[k][0]=i;
var.amicablePair[k++][1]=check(i);
}
}
return &var;
}


int main() {
// test case 1
{
int startnum = 5000;
int endnum = 7000;
struct amicable* ami;

ami = getAmicablePairs(startnum, endnum);

printf("{");
for(int i = 0; isize; i++)
{
printf("{%d, %d}",ami->amicablePair[i][0], ami->amicablePair[i][1]);
}
printf("}");
}

// test case 2
{
int startnum = 100;
int endnum = 2000;
struct amicable* ami;

ami = getAmicablePairs(startnum, endnum);

printf("{");
for(int i = 0; isize; i++)
{
printf("{%d, %d}",ami->amicablePair[i][0], ami->amicablePair[i][1]);
}
printf("}");
}

// test case 3

{
int startnum = 100;
int endnum = 10;
struct amicable* ami;

ami = getAmicablePairs(startnum, endnum);
if(ami!=NULL)
{
printf("{");
for(int i = 0; isize; i++)
{
printf("{%d, %d}",ami->amicablePair[i][0], ami->amicablePair[i][1]);
}
printf("}");
}
}
}




Solutions In Java.......
***********************

RSA DECRYPTION
=============


package test.rsadecryption;

public class RSADecryption {

public int getPlain(int cipherText)
{
//Write your code here
int m;
int c=cipherText;
if(c>=0)
{
m=((c*c)%33*(c*1)%33)%33;
}
else
{
return -1;
}

return m;

}
// You could use this sample code to test your functions
// Following main fucntion contains 3 representative test cases

public static void main(String args[]) {
//TestCase 1
try {
System.out.println("Testcase 1");
RSADecryption rsa = new RSADecryption();
int cipherText = 7;
int plainText = rsa.getPlain(cipherText);
System.out.println(plainText);
}
catch (Exception e) {
e.printStackTrace();
}
//TestCase 2
try {
System.out.println("Testcase 2");
RSADecryption rsa = new RSADecryption();
int cipherText = 152;
int plainText = rsa.getPlain(cipherText);
System.out.println(plainText);
}
catch (Exception e) {
e.printStackTrace();
}
//TestCase 3
try {
System.out.println("Testcase 3");
RSADecryption rsa = new RSADecryption();
int cipherText = 307;
int plainText = rsa.getPlain(cipherText);
System.out.println(plainText);
}
catch (Exception e) {
e.printStackTrace();
}
}
}



leastremainingtime
================


package test.leastremainingtime;
public class LeastRemainingTime {
int[] getSchedule(int browsingtime[], int time_slot) {
//Write your code here
int s[],ss[];
int i,j,k,l;
int noOfPerson=browsingtime.length;
int nSize=0;
s=new int[browsingtime.length];
ss=new int[browsingtime.length];
for(i=0;i
{
s[i]=i+1;
}
for(i=0;i
{
for(j=0;j
{
if(browsingtime[j]>browsingtime[j+1])
{
k=browsingtime[j];
browsingtime[j]=browsingtime[j+1];
browsingtime[j+1]=k;
l=s[j];
s[j]=s[j+1];
s[j+1]=l;
}
}
}
for(i=0;i
{
ss[i]=browsingtime[i];
}



l=0;
for(i=0;browsingtime[noOfPerson-1]>0;i++)
{
for(j=0;j
{
if(browsingtime[j]>0)
{
browsingtime[j]=browsingtime[j]-time_slot;
nSize=nSize+1;
}
}
}
int arr[]=new int[nSize];
l=0;
for(i=0;ss[noOfPerson-1]>0;i++)
{
for(j=0;j
{
if(ss[j]>0)
{
ss[j]=ss[j]-time_slot;
arr[l]=s[j];
l++;
}
}
}


//return new int[]{};
return arr;
}

// You could use this sample code to test your functions
// Following main fucntion contains 3 representative test cases

public static void main(String args[]) {
//TestCase 1:
try{
int[] browsingtime = {10, 7, 3, 4, 11};
int time_slot = 5;
int[] output = new LeastRemainingTime().getSchedule(browsingtime, time_slot);
if(output!=null && output.length>0)
for (int i = 0; i <>
System.out.print(output[i]+", ");
System.out.println();
}
catch(Exception e){
e.printStackTrace();
}
//TestCase 2:
try{
int[] browsingtime1 = {3, 7, 14, 4, 11};
int time_slot = 7;
int[] output1 = new LeastRemainingTime().getSchedule(browsingtime1, time_slot);
if(output1!=null && output1.length>0)
for (int i = 0; i <>
System.out.print(output1[i]+", ");
System.out.println();
}
catch(Exception e){
e.printStackTrace();
}
//TestCase 3:
try{
int[] browsingtime2 = {7, 10, 3, 4, 11};
int time_slot = 5;
int[] output2 = new LeastRemainingTime().getSchedule(browsingtime2, time_slot);
if(output2!=null && output2.length>0)
for (int i = 0; i <>
System.out.print(output2[i]+", ");
}
catch(Exception e){
e.printStackTrace();
}
}
}


BMI
==================================


package test.calcbmi;

public class BMI
{
public String getCategory(float height, float weight) {
///Write your Code Here
if(height <= 0 || weight <= 0 )
return "invalid";
double ht=height/100;
double bmiValue;
bmiValue = weight / (ht*ht);
if(bmiValue<15)
return "starvation";
else if(bmiValue >=15 && bmiValue <>
return "underweight";
else if( bmiValue >=18.5 && bmiValue <>
return "normal";
else if(bmiValue >= 25 && bmiValue <30)
return "overweight";
else if(bmiValue >=30 && bmiValue <>
return "obese";
else if(bmiValue >=40)
return "morbidly obese";
return "";
}

public static void main(String[] args)
{
//TestCase 1
try
{
float height = 200f;
float weight = 67.8f;
String catagory = new BMI().getCategory(height, weight);
System.out.println(catagory);
}
catch(Exception e)
{
System.out.println(e);
}

//TestCase 2
try
{
float height = 168f;
float weight = 70.2f;
String catagory = new BMI().getCategory(height, weight);
System.out.println(catagory);
}
catch(Exception e)
{
System.out.println(e);
}

//TestCase 2
try
{
float height = 0f;
float weight = 70.2f;
String catagory = new BMI().getCategory(height, weight);
System.out.println(catagory);
}
catch(Exception e)
{
System.out.println(e);
}
}
}




PRACTICAL NUMBER
=========================================


package com.adp.practicalnumbers;

public class PracticalNumbers {
public int[] getPracticalNumbers(int from, int to) {
//Write your code here
int ans[]=new int[getNoOfPracticalNumbers(from,to)];
int i=0;
while(from<=to)
{
if(check(from)==1)
ans[i++]=from;
from++;
}
return ans;
} // return new int[]{};
int find_diviser(int x[],int num)
{
int i=2,k=0;
x[k++]=1;
while(i<=num/2)
{ if(num%i==0)
x[k++]=i;
i++;
}
return k;
}
int check(int nondivisor,int divisors[],int size)
{
int result[]=new int[2000];
int difference,largest=divisors[0];
int i,j=0,k,l,m,n;
int sum=0;
for(i=size-1;i>=0;i--)
{

largest=divisors[0];
for(k=0;k
{
sum=sum+result[k];
}

difference=nondivisor-sum;


for(l=i;l>=0;l--)
{
if(divisors[l]==difference)
{
result[j]=difference;
j++;
return 1;
}
else if((largest
{
largest=divisors[l];
i=l;
}
}
result[j]=largest;
j++;
sum=0;
}
return 0;
}
int check(int num)
{
int x[]=new int[2000],i;
int n=find_diviser(x,num);
if(num==1)
return 1;
if(num%2!=0)
return 0;
for(i=2;i
{ if(check(i,x,n)==0)
{return 0;}
}
return 1;
}
int getNoOfPracticalNumbers(int from ,int to)
{
if(from<=0||to<=0||(to-from)>=10000)
return -1;
int i=0;
while(from<=to)
{
if(check(from)==1)
i++;
from++;
}
return i;
}
//return new int[]{};

// You could use this sample code to test your functions
// Following main fucntion contains 3 representative test cases
public static void main(String[] arg) {
PracticalNumbers pn = new PracticalNumbers();
//1st test case
int[] res = pn.getPracticalNumbers(1, 20);
for (int i = 0; i <>
System.out.print(res[i] + " ");
System.out.println();
//2nd test case
int[] res2 = pn.getPracticalNumbers(8000, 8200);
for (int i = 0; i <>
System.out.print(res2[i] + " ");
System.out.println();

//3rd test case
int[] res3 = pn.getPracticalNumbers(100, 250);
for (int i = 0; i <>
System.out.print(res3[i] + " ");
System.out.println();
}
}




********************** CHOCOLATE CHIPS****************
==========================================
package test.chocolatechip; public class ChocolateChip { public int getChocolateChip(double x[], double y[], int noOfCoordinates) { //Write your code here int count=0,k=0; int precount=0; if(noOfCoordinates<=0||noOfCoordinates>200) return -1; for(double i=2.5;i<=47.5;i+=5) { for(double j=2.5;j<=47.5;j+=5) { k=0;count=0; while(k=50||y[k]>=50) { return -1; } else { double a=(x[k]-i)*(x[k]-i)+(y[k]-j)*(y[k]-j); if(a<=6.25) count++; } k++; } if(precount


--
Hackerx Sasi
Don't ever give up.
Even when it seems impossible,
Something will always
pull you through.
The hardest times get even
worse when you lose hope.
As long as you believe you can do it, You can.

But When you give up,
You lose !
I DONT GIVE UP.....!!!


In three words I can sum up everything I've learned about life - it goes on......
with regards
prem sasi kumar arivukalanjiam

No comments:

Post a Comment

Slider

Image Slider By engineerportal.blogspot.in The slide is a linking image  Welcome to Engineer Portal... #htmlcaption

Tamil Short Film Laptaap

Tamil Short Film Laptaap
Laptapp

Labels

About Blogging (1) Advance Data Structure (2) ADVANCED COMPUTER ARCHITECTURE (4) Advanced Database (4) ADVANCED DATABASE TECHNOLOGY (4) ADVANCED JAVA PROGRAMMING (1) ADVANCED OPERATING SYSTEMS (3) ADVANCED OPERATING SYSTEMS LAB (2) Agriculture and Technology (1) Analag and Digital Communication (1) Android (1) Applet (1) ARTIFICIAL INTELLIGENCE (3) aspiration 2020 (3) assignment cse (12) AT (1) AT - key (1) Attacker World (6) Basic Electrical Engineering (1) C (1) C Aptitude (20) C Program (87) C# AND .NET FRAMEWORK (11) C++ (1) Calculator (1) Chemistry (1) Cloud Computing Lab (1) Compiler Design (8) Computer Graphics Lab (31) COMPUTER GRAPHICS LABORATORY (1) COMPUTER GRAPHICS Theory (1) COMPUTER NETWORKS (3) computer organisation and architecture (1) Course Plan (2) Cricket (1) cryptography and network security (3) CS 810 (2) cse syllabus (29) Cyberoam (1) Data Mining Techniques (5) Data structures (3) DATA WAREHOUSING AND DATA MINING (4) DATABASE MANAGEMENT SYSTEMS (8) DBMS Lab (11) Design and Analysis Algorithm CS 41 (1) Design and Management of Computer Networks (2) Development in Transportation (1) Digital Principles and System Design (1) Digital Signal Processing (15) DISCRETE MATHEMATICS (1) dos box (1) Download (1) ebooks (11) electronic circuits and electron devices (1) Embedded Software Development (4) Embedded systems lab (4) Embedded systems theory (1) Engineer Portal (1) ENGINEERING ECONOMICS AND FINANCIAL ACCOUNTING (5) ENGINEERING PHYSICS (1) english lab (7) Entertainment (1) Facebook (2) fact (31) FUNDAMENTALS OF COMPUTING AND PROGRAMMING (3) Gate (3) General (3) gitlab (1) Global warming (1) GRAPH THEORY (1) Grid Computing (11) hacking (4) HIGH SPEED NETWORKS (1) Horizon (1) III year (1) INFORMATION SECURITY (1) Installation (1) INTELLECTUAL PROPERTY RIGHTS (IPR) (1) Internal Test (13) internet programming lab (20) IPL (1) Java (38) java lab (1) Java Programs (28) jdbc (1) jsp (1) KNOWLEDGE MANAGEMENT (1) lab syllabus (4) MATHEMATICS (3) Mechanical Engineering (1) Microprocessor and Microcontroller (1) Microprocessor and Microcontroller lab (11) migration (1) Mini Projects (1) MOBILE AND PERVASIVE COMPUTING (15) MOBILE COMPUTING (1) Multicore Architecute (1) MULTICORE PROGRAMMING (2) Multiprocessor Programming (2) NANOTECHNOLOGY (1) NATURAL LANGUAGE PROCESSING (1) NETWORK PROGRAMMING AND MANAGEMENT (1) NETWORKPROGNMGMNT (1) networks lab (16) News (14) Nova (1) NUMERICAL METHODS (2) Object Oriented Programming (1) ooad lab (6) ooad theory (9) OPEN SOURCE LAB (22) openGL (10) Openstack (1) Operating System CS45 (2) operating systems lab (20) other (4) parallel computing (1) parallel processing (1) PARALLEL PROGRAMMING (1) Parallel Programming Paradigms (4) Perl (1) Placement (3) Placement - Interview Questions (64) PRINCIPLES OF COMMUNICATION (1) PROBABILITY AND QUEUING THEORY (3) PROGRAMMING PARADIGMS (1) Python (3) Question Bank (1) question of the day (8) Question Paper (13) Question Paper and Answer Key (3) Railway Airport and Harbor (1) REAL TIME SYSTEMS (1) RESOURCE MANAGEMENT TECHNIQUES (1) results (3) semester 4 (5) semester 5 (1) Semester 6 (5) SERVICE ORIENTED ARCHITECTURE (1) Skill Test (1) software (1) Software Engineering (4) SOFTWARE TESTING (1) Structural Analysis (1) syllabus (34) SYSTEM SOFTWARE (1) system software lab (2) SYSTEMS MODELING AND SIMULATION (1) Tansat (2) Tansat 2011 (1) Tansat 2013 (1) TCP/IP DESIGN AND IMPLEMENTATION (1) TECHNICAL ENGLISH (7) Technology and National Security (1) Theory of Computation (3) Thought for the Day (1) Timetable (4) tips (4) Topic Notes (7) tot (1) TOTAL QUALITY MANAGEMENT (4) tutorial (8) Ubuntu LTS 12.04 (1) Unit Wise Notes (1) University Question Paper (1) UNIX INTERNALS (1) UNIX Lab (21) USER INTERFACE DESIGN (3) VIDEO TUTORIALS (1) Virtual Instrumentation Lab (1) Visual Programming (2) Web Technology (11) WIRELESS NETWORKS (1)

LinkWithin