10656 - Maximum Sum (II)

All about problems in Volume CVI. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

asd

Postby darkos32 » Thu Aug 23, 2007 9:25 am

i got PE..can someone help me give me the sample input and output...

this is my code :

Code: Select all
got accepted..


thanks..
darkos32
New poster
 
Posts: 27
Joined: Tue Jul 25, 2006 8:10 am
Location: Indonesia

Postby alamgir kabir » Fri Nov 09, 2007 3:45 pm

Code: Select all
//remove


Thanks Jan for helping me.
Last edited by alamgir kabir on Wed Nov 14, 2007 3:06 pm, edited 2 times in total.
alamgir kabir
New poster
 
Posts: 37
Joined: Wed Oct 03, 2007 10:42 am

Postby Jan » Fri Nov 09, 2007 9:29 pm

Check the set very carefully.

Input:
Code: Select all
6
1
0
3
4
0
1
0

Output:
Code: Select all
1 3 4 1

Hope you get accepted.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Postby alamgir kabir » Wed Nov 14, 2007 3:04 pm

I do not consider this case.
Now I have acc it.
Thanks a lot Jan. I am greatful to u.

Code: Select all
//code removed


Thanks for helping me.
I hope u wil help me in future.
Last edited by alamgir kabir on Sun Nov 18, 2007 5:51 pm, edited 3 times in total.
alamgir kabir
New poster
 
Posts: 37
Joined: Wed Oct 03, 2007 10:42 am

Postby Jan » Wed Nov 14, 2007 8:03 pm

Try the case.

Input:
Code: Select all
3
0
0
0
0

Output:
Code: Select all
0

Hope it helps.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Re: 10656 - Maximum Sum (II)getting PE

Postby kbr_iut » Wed Apr 02, 2008 4:20 pm

now AC, code removed
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................
User avatar
kbr_iut
Experienced poster
 
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH

Re: 10656 - Maximum Sum (II)

Postby asif.mist » Tue Mar 22, 2011 10:48 am

is there any trailing space??
i got 5 PE....
asif.mist
New poster
 
Posts: 3
Joined: Wed Jan 26, 2011 4:43 pm

Re: 10656 - Maximum Sum (II)

Postby aaa111 » Fri Apr 29, 2011 4:51 pm

I am getting PE,please help:
Code: Select all
#include<stdio.h>

#define SIZE 1010

int main(void)
{
   int i,j,n,flag=0;
   unsigned int num[SIZE];

   while(1)
         {
         flag=0;
         scanf("%d",&n);
         if(n==0)
            break;
         for(i=0;i<n;i++)
            scanf("%u",&num[i]);
         
         if(num[0]==0)
            flag=1;

         i=0;
         if(flag==1)
            while((num[i]==0) && (i<n))
               i++;
               
         if(i==n)
             printf("0");
         else
            {
               for(j=i;j<n;j++)
                  {
                     if(num[j]!=0)
                        {
                        printf("%u",num[j]);
                        if(j!=(n-1))
                           printf(" ");
                        }
                  }
            }
   
         printf("\n");
         }
   
   return 0;
}
aaa111
New poster
 
Posts: 14
Joined: Sat Nov 21, 2009 2:55 pm

Re: 10656 - Maximum Sum (II)

Postby plamplam » Thu Jun 30, 2011 4:56 pm

Very easy problem
As the numbers are all non-negative, when you are taking input just store the number in an array if the number is not equal to 0. And later just print the array(with no trailing spaces).
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
User avatar
plamplam
Experienced poster
 
Posts: 151
Joined: Fri May 06, 2011 11:37 am

Re: 10656 - Maximum Sum (II)

Postby blckhrt » Mon Aug 22, 2011 8:36 pm

pls help..um continuosly getting wa in this code..wat's wrong???


#include<stdio.h>
int main()
{
long long int n,i,j,k,flag,num[10000];
while(scanf("%lld",&n)==1)
{
if(n==0)
break;
flag=0;
for(i=0;i<n;i++)
{
scanf("%lld",&num[i]);
if(num[i]==0)
{
flag++;
}
}

if(flag==n)
printf("0\n");
else
{
for(j=0;j<n;j++)
{
if(num[j]==0)
continue;
printf("%lld ",num[j]);
}

printf("\n");
}

}
return 0;
}
blckhrt
New poster
 
Posts: 2
Joined: Wed May 04, 2011 8:25 pm
Location: Chittagong

Previous

Return to Volume CVI

Who is online

Users browsing this forum: Google [Bot] and 1 guest