139 - Telephone Tangles

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

Moderator: Board moderators

paulhryu
New poster
Posts: 45
Joined: Sat Jan 26, 2002 2:00 am
Contact:

Post by paulhryu » Tue Feb 12, 2002 1:45 am

One of those really murky things on this page is how they put a picture for the output and expect us to figure out what's going on.
Okay, problem 139. It looked really easy so I tried it, not heeding that 2% success rate. And I seem to have a perfectly good program, but I don't get how you're supposed to output. Well, anybody help?
And while you're at it, can you look at this and tell me if I'm even close to being remotely done?
How can such a seemingly easy problem only have like 25 solvers? Am I missing something? This site should really give us test values for what we get wrong... that would be so useful.
#include <iostream.h>
#include <fstream.h>
#include <string.h>

#ifdef ONLINE_JUDGE
#define ins cin
#define outs cout
#else
#define ins fin
#define outs fout
ifstream fin("myprog.in");
ofstream fout("myprog.out");
#endif

typedef struct {
char code[10];
char name[30];
int price;
} locality;

locality areas[10000];
int narea;

int main() {
int len, min, i, j;
char telly[20];

while(ins >> telly) {
if(strcmp(telly, "000000") == 0) break;
strcpy(areas[narea].code, telly);

len = 0;
for(;;) {
ins >> areas[narea].name[len];
if(areas[narea].name[len] == '$') break;
len++;
}

areas[narea].name[len++] = '';

ins >> areas[narea].price;
narea++;
}

outs.setf(ios::fixed);
outs.precision(2);

while(ins >> telly) {
if(telly[0] == '#') break;
ins >> min;

if(telly[0] != '0') {
outs << telly << " Local "
<< telly << " " << min << " 0.00 0.00n";
} else {
for(i = 0; i < narea; i++) {
len = strlen(areas.code);
for(j = 0; j < len; j++)
if(areas.code[j] != telly[j]) break;

if(j == len)
break;
}

if(i == narea) {
outs << telly << " Unknown "
<< min << " " << -1. << endl;
} else {
outs << telly << " " << areas.name << " "
<< &telly[len] << " " << min << " "
<< areas.price * .01 << " "
<< areas.price * min * .01 << endl;
}
}
}

return 0;
}

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel » Tue Feb 12, 2002 8:27 pm

Test this input with your program (the problem is not as easy as you thought):

Code: Select all

088925 Broad-wood$ 81
03 Arrow.town$ 38
0061 Australia$ 140
0911 N

paulhryu
New poster
Posts: 45
Joined: Sat Jan 26, 2002 2:00 am
Contact:

Post by paulhryu » Thu Feb 14, 2002 3:59 am

Wow, your test case got me to correct my problem. Now I'm the 28th person to solve that one, and the 26th to get a presentation error. Haha, that's funny. Thanks for the help. Now my name is one the ranklist, smack right there, "Ho Seung Ryu," though I am kinda using excessive time & mem. I'll look into it later.

Lawrence
New poster
Posts: 17
Joined: Sat Feb 09, 2002 2:00 am
Location: China
Contact:

Post by Lawrence » Mon Feb 18, 2002 9:30 am

I have passed your case, but why I still got Wrong Answer?
Code:
/* @JUDGE_ID:6511NH 139 C "" */
#include <stdio.h>
#include <string.h>

#define MAXPLC 2000

char codes[MAXPLC][7];
char names[MAXPLC][26];
double fees[MAXPLC];

void main()
{
#ifdef ONLINE_JUDGE
FILE *fp=stdin;
#else
FILE *fp=fopen("139.in","r");
#endif
char buf[1023];
int i=0,j,k;
char *ptr;
char c;
char number[50];
int length;
float aprice;
while(1)
{
fgets(buf,sizeof(buf),fp);
if(!strcmp(buf,"000000n"))
break;
ptr = buf;
j=0;
while(*ptr!=' ')
{
codes[j++]=*ptr;
ptr++;
}
codes[j]='';
j=0;
ptr++;
while(*ptr!='$')
{
names[j++]=*ptr;
ptr++;
}
names[j]='';
ptr++;
sscanf(ptr,"%f",&aprice);
fees=aprice/100.0;
i++;
}
while(1)
{
memset(number,0,sizeof(number));
c=fgetc(fp);
if(c=='#')
break;
else
ungetc(c,fp);
fscanf(fp,"%s %dn",number,&length);
if(number[0]!='0')
printf("%-16s%-20s%15s%5d%6.2f%7.2fn",number,"Local",number,length,0.00,0.00);
else
{
for(j=0;j<i;j++)
{
ptr=strstr(number,codes[j]);
if(ptr==number)
{
ptr+=strlen(codes[j]);
if(strlen(ptr)<4 || (strlen(ptr)>10 && number[1]=='0') || (strlen(ptr)>7 && number[1]!='0'))
printf("%-16s%-35s%5d%13.2fn",number,"Unknown",length,-1.00);
else
printf("%-16s%-25s%10s%5d%6.2f%7.2fn",number,names[j],ptr,length,fees[j],fees[j]*length);
break;
}
}
if(j==i)
printf("%-16s%-35s%5d%13.2fn",number,"Unknown",length,-1.00);
}
}
}

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel » Mon Feb 18, 2002 3:28 pm

Perhaps there is one testcase with
088 Arrowtown$ 20
088925 Broadwood$ 81
000000
0889251234567 22
#
I have considered this in my program, and you could easily change your program (only insert continue instead of printf).

Lawrence
New poster
Posts: 17
Joined: Sat Feb 09, 2002 2:00 am
Location: China
Contact:

Post by Lawrence » Sat Feb 23, 2002 4:04 pm

You are right, and I've got a P.E. now! Thanks very much.

C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 » Thu Feb 28, 2002 6:46 am

The numbers on top of the columns tell you what character to align it with. Doing so should fix the Presentation Error.

Max Fate
New poster
Posts: 6
Joined: Fri Mar 15, 2002 2:00 am

Post by Max Fate » Fri Mar 15, 2002 9:12 pm

No, such align doesn't fix PE. Maybe there is a person got Accepted but he only could help

<font size=-1>[ This Message was edited by: Max Fate on 2002-03-17 09:53 ]</font>

dh3014
New poster
Posts: 24
Joined: Tue Mar 26, 2002 2:00 am
Location: Taiwan
Contact:

Post by dh3014 » Thu Mar 28, 2002 9:16 am

Is there any tricks on this problem?
I've got AC before the problem is rejudged.

Now I cannot find out what's the reason I
got WA, does anybody know what should I notice?

FlyDeath
Learning poster
Posts: 73
Joined: Wed Jan 02, 2002 2:00 am
Location: Taiwan

Post by FlyDeath » Thu Mar 28, 2002 3:23 pm

There will be something like this:
01 MYHOME$30
012 MYFREIND$40
000000
0123333333 50
#
the output will be:(p.s. I ignore the spaces)
0123333333 MYFRIEND 3333333 504.00 200.00
(50 and 4.00 stick together ,don't be afraid,just print it.)
MYHOME is not acceptable.Why?Because there id 8 digits after "01".It's illegal.

and if there is a input like this:

Code: Select all

03   MY GOD
000000
0333333 10
the spaces in front of name and the spaces between name should be printed

Good luck!

<font size=-1>[ This Message was edited by: FlyDeath on 2002-03-28 14:23 ]</font>

Lawrence
New poster
Posts: 17
Joined: Sat Feb 09, 2002 2:00 am
Location: China
Contact:

Post by Lawrence » Sat Mar 30, 2002 9:41 am

And if you still cannot get passed, look at the previous post on this problem and you will find it.

dh3014
New poster
Posts: 24
Joined: Tue Mar 26, 2002 2:00 am
Location: Taiwan
Contact:

Post by dh3014 » Sun Mar 31, 2002 2:44 pm

I've passed (P.E also)
Thanks everybody

Archangel
New poster
Posts: 29
Joined: Wed Jun 26, 2002 9:00 am

Post by Archangel » Wed Jul 03, 2002 10:28 pm

A little question~^^
What should be the output when this kind of input?

01 abcd$20
012 efgh$30
000000
012345 40
#

The output should be "unknown" or "abcd"?? :D

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

139 - Telephone Tangles

Post by htl » Sat Jul 13, 2002 1:53 am

Why does the code get RE? Is the input data over 1000?
[c]
#include<stdio.h>
#include<string.h>
void main(void)
{
int n,x,time,len,y,z,point,len2;
double t;
char buffer[50],c;
struct telecom
{
char num[7],name[26];
double fee;
}data[1000];
for(n=0;;)
{
scanf("%s",buffer);
if(strcmp(buffer,"000000")==0)
break;
strcpy(data[n].num,buffer);
c=getchar();
gets(buffer);
for(x=0;buffer[x]!='$';x++)
data[n].name[x]=buffer[x];
data[n].name[x]='\0';
for(t=0,point=-1;buffer[x]!='\0';x++)
if(buffer[x]>='0' && buffer[x]<='9')
{
t=t*10+buffer[x]-'0';
if(point>=0)
point++;
}
else if(buffer[x]=='.')
point++;
for(x=0;x<point;x++)
t/=10;
data[n].fee=t;
n++;
}
while(1)
{
scanf("%s",buffer);
if(strcmp(buffer,"#")==0)
break;
scanf("%d",&time);
if(buffer[0]!='0')
{
printf("%-16sLocal%*s%7d 0.00 0.00\n",buffer,30,buffer,time);
}
else
{
for(x=0;x<n;x++)
{
len=strlen(data[x].num);
len2=strlen(buffer);
if(len>strlen(buffer) || len>15)
continue;
if(len>=3 && data[x].num[0]=='0' && data[x].num[1]=='0' && (len2-len<4 || len2-len>10))
continue;
if(len>=2 && data[x].num[0]=='0' && data[x].num[1]!='0' && (len2-len<4 || len2-len>7))
continue;
for(y=0;y<len;y++)
if(data[x].num[y]!=buffer[y])
break;
if(y==len)
break;
}
if(y==len)
{
printf("%-16s",buffer);
printf("%s",data[x].name);
for(z=0;z<35-strlen(data[x].name)-(strlen(buffer)-len);z++)
printf(" ");
for(z=len;buffer[z]!='\0';z++)
printf("%c",buffer[z]);
t=time;
printf("%7d%24.2lf%7.2lf\n",time,data[x].fee/100,t*data[x].fee/100);
}
if(x==n)
{
printf("%-16s",buffer);
printf("%-35s","Unknown");
printf("%7d",time);
printf("%31s\n","-1.00");
}
}
}
}
[/c]

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

Post by htl » Sat Jul 13, 2002 10:01 am

I've modified it and get WA.
[c]
#include<stdio.h>
#include<string.h>
void main(void)
{
int n,x,time,len,y,z,point,len2;
double t;
char buffer[50],c;
struct telecom
{
char num[7],name[26];
double fee;
}data[2000];
for(n=0;n<2000;)
{
scanf("%s",buffer);
if(strcmp(buffer,"000000")==0)
break;
strcpy(data[n].num,buffer);
c=getchar();
gets(buffer);
for(x=0;buffer[x]!='$';x++)
data[n].name[x]=buffer[x];
data[n].name[x]='\0';
for(t=0,point=-1;buffer[x]!='\0';x++)
if(buffer[x]>='0' && buffer[x]<='9')
{
t=t*10+buffer[x]-'0';
if(point>=0)
point++;
}
else if(buffer[x]=='.')
point++;
for(x=0;x<point;x++)
t/=10;
data[n].fee=t;
n++;
}
while(1)
{
scanf("%s",buffer);
if(strcmp(buffer,"#")==0)
break;
scanf("%d",&time);
if(buffer[0]!='0')
printf("%-16sLocal%*s%7d%24s%7s\n",buffer,30,buffer,time,"0.00","0.00");
else
{
for(x=0;x<n;x++)
{
len=strlen(data[x].num);
len2=strlen(buffer);
if(len>strlen(buffer) || len>15)
continue;
if(len>=3 && data[x].num[0]=='0' && data[x].num[1]=='0' && (len2-len<4 || len2-len>10))
continue;
if(len>=2 && data[x].num[0]=='0' && data[x].num[1]!='0' && (len2-len<4 || len2-len>7))
continue;
for(y=0;y<len;y++)
if(data[x].num[y]!=buffer[y])
break;
if(y==len)
break;
}
if(y==len)
{
printf("%-16s",buffer);
printf("%s",data[x].name);
for(z=0;z<35-strlen(data[x].name)-(len2-len);z++)
printf(" ");
for(z=len;buffer[z]!='\0';z++)
printf("%c",buffer[z]);
t=time;
printf("%7d%24.2lf%7.2lf\n",time,data[x].fee/100,t*data[x].fee/100);
}
if(x==n)
{
printf("%-16s",buffer);
printf("%-35s","Unknown");
printf("%7d",time);
printf("%31s\n","-1.00");
}
}
}
}
[/c]

Post Reply

Return to “Volume 1 (100-199)”