I have compiled your code,
but still crash in this input:
Input:
9 7 6 2
2 5 6
45 23 91
5 9 19
Regards,
RS
![:-?](./images/smilies/icon_confused.gif)
Moderator: Board moderators
Code: Select all
#include <stdio.h>
main() {
long i,j,m,n,t,max,waste,time;
while( scanf("%ld %ld %ld",&m,&n,&t)!=EOF ) {
max=0;
time=0;
waste=0;
for(i=0;m*i<=t;i++)
for(j=0;m*i+n*j<=t;j++) {
if(m*i+n*j==t && i+j>max) { max=i+j; }
else if(i+j>waste) { waste=i+j; time=m*i+n*j; }
}
if(max==0) printf("%ld %ld\n",waste,t-time);
else printf("%ld\n", max);
}
return 0;
}
Code: Select all
#include<stdio.h>
int main()
{
int m,n,t,time;
int n1,n2,m1,m2,p,q,beer;
while(scanf("%d%d%d",&m,&n,&t)==3)
{
beer=t;
m1=m2=0;
if(m==1 || n==1)
{
printf("%d\n",t);
continue;
}
if(n<m)
{
time=m;
m=n;
n=time;
}
p=t/n;
int tag=0;
for(n1=0;n1<=p;n1++)
{
time=t-n1*n;
if(time>=0 && time%m==0)
{
if((n1+time)/m>m1)
{
m1=n1+time/m;
tag=1;
}
}
else if(time>=0 && (time%m)!=0)
{
q=time/m;
if((time-q*m)<beer)
{
m2=n1+q;
beer=time-q*m;
}
else if((time-q)==beer)
if(n1+q>m2)
m2=n1+q;
}
}
if(tag)printf("%d\n",m1);
else printf("%d %d\n",m2,beer);
}
}