591  Box of Bricks
Moderator: Board moderators

 New poster
 Posts: 1
 Joined: Sun Aug 27, 2006 2:28 am
 Location: Bangladesh
 Contact:
591
Can anyone please tell me what's wrong with this code:
#include <stdio.h>
main()
{
int n,h[200],sum=0,sum2=0,h1[100000];
int k=0,i,j;
while(scanf("%d",&n) && n!=0)
{
for(i=0;i<n;i++)
{
scanf("%d",&h);
sum+=h;
}
sum=sum/n;
for(i=0;i<n;i++)
{
if(hsum>0)
{
sum2+=(hsum);
}
}
h1[k]=sum2;
k++;
sum=sum2=0;
}
for(j=0;j<k;j++)
{
printf("set #%d\n",j+1);
printf("The minimum number of moves is %d\n\n",h1[j]);
}
return 0;
}
thanks
#include <stdio.h>
main()
{
int n,h[200],sum=0,sum2=0,h1[100000];
int k=0,i,j;
while(scanf("%d",&n) && n!=0)
{
for(i=0;i<n;i++)
{
scanf("%d",&h);
sum+=h;
}
sum=sum/n;
for(i=0;i<n;i++)
{
if(hsum>0)
{
sum2+=(hsum);
}
}
h1[k]=sum2;
k++;
sum=sum2=0;
}
for(j=0;j<k;j++)
{
printf("set #%d\n",j+1);
printf("The minimum number of moves is %d\n\n",h1[j]);
}
return 0;
}
thanks

 Learning poster
 Posts: 54
 Joined: Mon Jan 02, 2006 3:06 am
 Location: Dhaka,Bangladesh
 Contact:
your mistake is:you take all the inputs together and then print their outputs, but actually this is not the usual style for uva problems.
here you'll have to take an input, then print its output,then take another input........this process will go on until the end of the file.
you can have a look on the sample code provided in this site.
http://onlinejudge.uva.es/problemset/data/p100.c.html
best regards.
here you'll have to take an input, then print its output,then take another input........this process will go on until the end of the file.
you can have a look on the sample code provided in this site.
http://onlinejudge.uva.es/problemset/data/p100.c.html
best regards.
Sanjana
591
I really can't find any mistakes...Pls help me~~~
#include <iostream>
using namespace std;
int main(){
int count=0;
int block;
long sum;
long result;
long diff;
int i;
do{
sum=0;
result=0;
cin>>block;
if (block==0){
break;}
count++;
int a[block];
for (i=0;i<block;i++){
cin>>a;
sum+=a;
}
for (i=0;i<block;i++){
diff=asum/block;
if (diff>0){
result+=diff;}
}
cout<<"Set #"<<count<<endl;
cout<<"The minimum number of moves is "<<result<<endl<<endl;
} while (1);
return 0;
}
#include <iostream>
using namespace std;
int main(){
int count=0;
int block;
long sum;
long result;
long diff;
int i;
do{
sum=0;
result=0;
cin>>block;
if (block==0){
break;}
count++;
int a[block];
for (i=0;i<block;i++){
cin>>a;
sum+=a;
}
for (i=0;i<block;i++){
diff=asum/block;
if (diff>0){
result+=diff;}
}
cout<<"Set #"<<count<<endl;
cout<<"The minimum number of moves is "<<result<<endl<<endl;
} while (1);
return 0;
}

 New poster
 Posts: 13
 Joined: Sat Oct 07, 2006 6:42 pm
 Contact:
591 with P.E
This is my code cant find why i get P.E
plz help me
#include<iostream>
using namespace std;
int main()
{
int i=1,k,h[100];
cin>>k;
while(k!=0)
{
int sum=0;
for(int j=0;j<k;j++)
{
cin>>h[j];
sum=sum+h[j];
}
int t=sum/k;
int s=0;
for(int j=0;j<k;j++)
{
if(h[j]>t)
s=s+(h[j]t);
}
cout<<"Set #"<<i<<endl;
cout<<"The minimum number of moves is "<<s<<"."<<endl;
cin>>k;
i++;
}
return 0;
}
thanx in advance
plz help me
#include<iostream>
using namespace std;
int main()
{
int i=1,k,h[100];
cin>>k;
while(k!=0)
{
int sum=0;
for(int j=0;j<k;j++)
{
cin>>h[j];
sum=sum+h[j];
}
int t=sum/k;
int s=0;
for(int j=0;j<k;j++)
{
if(h[j]>t)
s=s+(h[j]t);
}
cout<<"Set #"<<i<<endl;
cout<<"The minimum number of moves is "<<s<<"."<<endl;
cin>>k;
i++;
}
return 0;
}
thanx in advance

 New poster
 Posts: 4
 Joined: Tue Oct 03, 2006 10:29 pm
Hey...
Try changing line
with line
Then, you'll get ACC
Try changing line
Code: Select all
cout<<"The minimum number of moves is "<<result<<endl<<endl;
Code: Select all
cout<<"The minimum number of moves is "<<result<<"."<<endl<<endl;

 New poster
 Posts: 4
 Joined: Tue Oct 03, 2006 10:29 pm
Try changing line
with line
Good luck
Code: Select all
cout<<"The minimum number of moves is "<<s<<"."<<endl;
Code: Select all
cout<<"The minimum number of moves is "<<s<<"."<<endl<<endl;
 Debashis Maitra
 Learning poster
 Posts: 62
 Joined: Sun Jul 09, 2006 8:31 am
 Location: University of Dhaka
 Contact:
591
can any one plz tell me what is the prob in my following program
#include<stdio.h>
main()
{
int x[100],n,i,y,z,l,k,j=1;
while(1)
{
y=0; l=0;
scanf("%d",&n);
if(n==0)
break;
for(i=0;i<n;i++)
{
scanf("%d",&x);
y+=x;
}
z=y/n;
printf("set# %d\n",j);
for(i=0;i<n;i++)
{
if(x>z)
l+=(xz);
}
printf("The minimum number of moves is: %d\n",l);
j++;
}
}
#include<stdio.h>
main()
{
int x[100],n,i,y,z,l,k,j=1;
while(1)
{
y=0; l=0;
scanf("%d",&n);
if(n==0)
break;
for(i=0;i<n;i++)
{
scanf("%d",&x);
y+=x;
}
z=y/n;
printf("set# %d\n",j);
for(i=0;i<n;i++)
{
if(x>z)
l+=(xz);
}
printf("The minimum number of moves is: %d\n",l);
j++;
}
}
Two things:
should be
And you forgot this line:
Code: Select all
printf("set# %d\n",j);
Code: Select all
printf("Set #%d\n",j);
Output a blank line after each set.

 New poster
 Posts: 6
 Joined: Wed Mar 21, 2007 7:24 pm
591: PE problem ...
HI, Having eventually managed to get an AC I know get a PE. I know it's not a major issue but I'd like to clear up what I might have got wrong. I copy below the i/o parts of the cod ein the hope that someone will guide me.
With thanks
With thanks
Code: Select all
cin >> stackTotal;
// outer loop only entered if the stack total is not zero
...
cin >> stacks[i];
...
// process the stuff and do some calculations
// print out the result
cout << endl << "Set #" << count << endl;
cout << "The minimum number of moves is " << answer << "." << endl << endl;

 New poster
 Posts: 39
 Joined: Mon Dec 04, 2006 2:18 pm
 Location: Bangladesh(CSE DU)
 Contact:
Hi,
There is a wrong in your output section. Your output section is
Change it to
I think it will help you.
ABDULLAH.
There is a wrong in your output section. Your output section is
Code: Select all
cin >> stackTotal;
// outer loop only entered if the stack total is not zero
...
cin >> stacks[i];
...
// process the stuff and do some calculations
// print out the result
cout << endl << "Set #" << count << endl;
cout << "The minimum number of moves is " << answer << "." << endl << endl;
Code: Select all
cout <<"Set #" << count << endl;
ABDULLAH.
can someone please give me some help in speeding up my program as i'm getting tle...
thanks
Code: Select all
#include <iostream>
int main()
{
int n,h=0,average=0,moves=0,set=1;
int* heights = new int [60];
a:
scanf("%d",&n);
if(n<1)
{
return 0;
}
else
{
while(h<n)
{
scanf("%d",&heights[h]);
average+=heights[h];
h++;
}
h=0;
average=average/n;
while(h<n)
{
if(heights[h]>average)
{
moves+=heights[h]average;
}
h++;
}
printf("Set #%d\nThe minimum number of moves is %d.\n\n",set,moves);
moves=0;set++;
goto a;
}
}