English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Input
The input will contain a sequence of integers (positive, negative, and/or zero). Maximum length of the sequence will be 25
Output
The output for this program will be a line indicating the length of the longest subsequence, a new line, a dash character ('-'), a new line, and then the subsequence itself printed with one integer per line. If the input contains more than one longest subsequence, the output file should print the one that occurs last in the input .
Notice that the second 8 was not included -- the subsequence must be strictly increasing.
Sample Input
-7
10
9
2
3
8
8
6
Sample Output
4
-
-7
2
3
8

2007-03-22 05:01:05 · 2 answers · asked by atul a 1 in Computers & Internet Programming & Design

2 answers

#include

void main()
{
int length[100],uptd_addr[100];
int str_addr[100],orig_arr[100];
int ans[100];
int ptr,end=0,update=0,i;
int num,cntr=0,grtst,strt_loc;

printf("enter the total number of elements u want to enter");
scanf("%d",&num);
printf("\n Enter the damn elements\n");
for(i=0;i scanf("%d",&orig_arr[i]);

/*initializing the arrays*/
length[0]=1;
str_addr[0]=0;
uptd_addr[0]=0;


for(ptr=1;ptr {

for(i=0;i<=end;i++)
{
if(orig_arr[ptr]
>orig_arr[uptd_addr[i]])
{
length[i]=length[i]+1;
uptd_addr[i]=ptr;
update=1;
}
}


if(update==0)
{
end++;
length[end]=1;
uptd_addr[end]=ptr;
str_addr[end]=ptr;
}
update=0;

}


grtst=length[0];

for(i=1;i<=end;i++)//checks the gteatest substring available
{
if(length[i]>=grtst)
{
grtst=length[i];
cntr=i;
}
}


strt_loc=str_addr[cntr];
ans[0]=orig_arr[strt_loc];
i=0;
for(ptr=strt_loc+1;ptr ;ptr++)
{
if(orig_arr[ptr]>ans[i])
{
i++;
ans[i]=orig_arr[ptr];

}
}

printf("\n*******output***
***********");
printf("\n%d",length[cntr]);
printf("\n");
printf("\n-");
printf("\n");
for(int j=0;j<=i;j++)
printf("\n%d",ans[j]);

}


if u hav a better solution or any effecient algo ..pls mail me at mickeystaines@yahoo.com
explaination of this program is left to u as homework....
n dont post such programs ny more...coz i've my exams cumin up n got to study many other stupid subjects..bye...

ps-some of the lines have been continued to the next line..coz this editor doesnt show the whole of it if it is in one line....pls join them back....

2007-03-23 03:20:29 · answer #1 · answered by freeze 2 · 0 0

The devil is in the foremost factors. If we've been speaking a pair of sequence of the type (a million-a1/a2) + (a million-a3/a4) + (a million-a5/a6) +.... definite, it is made to converge, if the words have been (a million - n²/(n²+a million)). even with the undeniable fact that, we are speaking a pair of sequence of the type (a million-a1/a2) + (a million-a2/a3) + (a million-a3/a4) +.... then the words would could be of the type (a million - f(n)/f(n+a million)), in view that ensures that numerator of a time era is the comparable by way of fact the denominator of the previous. Now, f(n) and f(n+a million) the two being integers, the smallest difference between them can purely be a million, so as that a time era would be of the type (a million - n/(n+a million)), which reduces to (a million/(n+a million)), meaning this would be a harmonic sequence, a properly prevalent divergent sequence. (Addendum: Am now awaiting jaz_will's evidence with abated breath! I agree that my evidence isn't complete, yet observe that a million - f(n)/(f(n)+a million) = a million/(f(n)+a million) is often smaller than a million - f(n)/(f(n+a million), for any monotonically increasing f(x) that usually return an integer. Or so i think of. all and sundry?) Addendum 2: Hats off to jaz_will.

2016-12-15 06:20:20 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers