## 643 - Bulk Mailing

Moderator: Board moderators

mag
New poster
Posts: 4
Joined: Wed Oct 16, 2002 6:22 am
Location: Novosibirsk
Contact:

### 643 - Bulk Mailing

Hi.

There is one hole in the problem:
imagine we have 16 letters with the same first 3 digits, but with different last 2 digits.

We could pack 15 letters into the one (!) 3-digit-bundle. But how we could choose letter should be sent first-class?

Please, tell me, where I was wrong.
wbr, Mikhail A Gusarov aka MAG
mailto:gusarov@ccfit.nsu.ru

Per
A great helper
Posts: 429
Joined: Fri Nov 29, 2002 11:27 pm
Location: Sweden
The problem clearly states that:
If there are 16 letters and you have to make a 3-digit bundle, you should combine the 15 with lowest zip code.
One thing that is somewhat fuzzy is the letter count:
with the number of letters and number of bundles for each zip code
Suppose the number of letters for a zip code is 16, so that we can only make one bundle with 15 letters. Should we print 15 or 16 as the letter count? 15 seems reasonable, but "the number of letters" for that zip code is 16. I've tried both, but get WA.

Per
A great helper
Posts: 429
Joined: Fri Nov 29, 2002 11:27 pm
Location: Sweden
Finally found the answer, in case anyone is interested.

We do indeed print 15 as the letter count in the above case.

Another hint: the sample output is somewhat broken. We should print a blank line between "INVALID ZIP CODES" and the first invalid zip code.

ginie
New poster
Posts: 4
Joined: Sun Feb 20, 2005 11:46 pm

Hi!!

I just get WA with that problem, but i've done lots of test with my code and it works ok. The only point i'm not so sure about is the way i must read the input . PLEASE HELP.
Here's my code.

#include <stdio.h>
#include <iostream.h>
#include <iomanip>
#include <string.h>
#include <math.h>

typedef char Tfals[10];

void main()
{
int i,j,numfals,error,c,aux,d,lon,bundles,y,bundlestotals,letterstotals;
char x[10];
int zip[100000],z1[100000];
Tfals cerror[100];

numfals=numfals^numfals;letterstotals=letterstotals^letterstotals;bundlestotals=bundlestotals^bundlestotals;
for(i=0; i<100000; i++){zip=zip^zip;z1=z1^z1;}

while(cin)
{
error=error^error;
cin.getline(x, 10, '\n');
if (lon=strlen(x)!=5) error=1;
else
{
i=i^i;c=c^c;
while((!error)&&(i<5))
{
y=((int)x)-'0';
if ( (y<0)||(y>9) ) error=1;
else {c=c+y*pow(10,4-i);i++;}
}
if (!error)
{
if(c!=0) { zip[c]++; letterstotals++;}
else { error=1; for(i=0; i<5; i++) x='0';}
}
}
if(error)
{ i=i^i;aux=aux^aux;
while( (i<=numfals) && !aux )
{
if(strcmp(x,cerror)==0) aux=1;
else i++;
}
if(!aux) { strcpy(cerror[numfals],x); numfals++;}
}
}

cout<<"ZIP"<<" "<<"LETTERS"<<" "<<"BUNDLES"<<"\n"<<"\n";

for (i=1; i<100000; i++)
{
if(zip>9)
{
if ((zip[i]%15>4)||(zip[i]/15>1)) { bundles=zip[i]/15+1; aux=zip[i];zip[i]=zip[i]^zip[i];}
else if (zip[i]%15==0) { bundles=zip[i]/15; aux=zip[i]; zip[i]=zip[i]^zip[i];}
else
{ bundles=1;aux=15;
zip[i]=zip[i]-15;
}
bundlestotals=bundlestotals+bundles;
cout.fill('0');
cout.width(5);cout.setf(ios::right);
cout << i;
cout<<" "<< aux <<" "<< bundles<<"\n";
}
}

cout<<"\n";

for( j=0; j<1000; j++)
{
c=c^c;
for( i=1; i<100; i++)
c=c+zip[j*100+i];
if( c>9 )
{
if ((c%15>4)||(c/15>1)) bundles=c/15+1;
else if (c%15==0) bundles=c/15;
else
{ bundles=1;
d=c%15; aux=99;
while(d>0)
{
if(zip[j*100+aux]>d) { z1[j*100+aux]=d;d=d^d;}
else
{
z1[j*100+aux]=zip[j*100+aux];
d=d-zip[j*100+aux]; aux--;
}
}
}
bundlestotals=bundlestotals+bundles;
cout.fill('0');
cout.width(2);cout.setf(ios::right);
cout << j;
cout<< "xx" <<" "<< c <<" "<< bundles<<"\n";
}
else { for(i=1; i<100; i++)
z1[100*j+i]=zip[100*j+i];}
}

cout<<"\n";

for( j=0; j<100000; j++)
if(z1[j]>0) { cout.fill('0');cout.width(5);cout.setf(ios::right);cout << j;cout<<" "<< z1[j] <<" "<< "0\n";}

cout<<"\n"<<"TOTALS"<<" "<< letterstotals <<" "<< bundlestotals<<"\n";
cout<<"\n"<<"INVALID ZIP CODES"<<"\n";

for( j=0; j<numfals; j++)
cout<< cerror[j]<<"\n";
}

tsengct
New poster
Posts: 5
Joined: Mon Aug 27, 2007 7:11 am
The sample input of problem 643 on the web page has trailing spaces. But from the sample output the spaces seems should be ignored. Is it right that I can/need to remove all the spaces?

If not so, how do I deal with the following inputs? (underline means space)
12345___
12345__
12_345

The secind problem is that the problem statement states that I should single space the reports but the sample output doesn't seem so.

tsengct
New poster
Posts: 5
Joined: Mon Aug 27, 2007 7:11 am
Finally got AC.
Just discard the confusing statements about the output format in the problem statement. Follow the sample output format.
1. There's no blank line between "INVALID ZIP CODES" and the first invalid zip code.
2. The numbers of valid zip codes are not single spaced, but aligned by the last digit.