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

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 139 help

Post by lighted »

I finally got accepted!!!
name should be read ( including space(s) ) until character '$'
it can be done in this way

Code: Select all

   gets(s);

   sscanf(s, " %s %[^$]$%lf", code[n], name[n], &price[n]);
it is neccessary to check subsciber
you need to check the subscriber IDD(4-10) STD(4-7)

Code: Select all

00 Los Angelos
00 is invalid IDD code but can be valid STD code, so must check it.
I just found the problem and got AC. :D
For those got PE, please consider the case where the Local phone numbers with more than 10 digits.
I didn't consider this and got accepted
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 139 - Telephone Tangles

Post by uDebug »

First off, there's a lot of hype surrounding this problem: Maybe even a bit too much. If you read this thread it sounds daunting. But, on the contrary, this problem not impossible to solve. It's tricky but pretty neat. So, don't let what you read in the thread dampen your spirits.

Next, to add to all the excellent points lighted shared, here's some things I discovered on my journey

(1) The first part of the input can be gotten using the following piece of skeleton code (in C++)

Code: Select all

int i;
string aLine, numberStr;

/* Process the first part of the input */
while(1) {
	/* Read the line */
	getline(cin, aLine);
		
	/* Clear the number and reset i*/
	string numberStr.clear(); i = 0;
		
	/* Get the number */
	while(isdigit(aLine[i])) {
		numberStr.push_back(aLine[i]);
		i++;
	}
		
	/* If this number 6 zeros, then break */
	if(numberStr == "000000") {
		break;
	}
		
	/* Process the rest of the line */
	...
}
As others have mentioned make sure you account for location names that have spaces in them. So, for example

Code: Select all

Riverside Village
or

Code: Select all

Jago de la Vega
(2) For the second part of the input, I used something like this

Code: Select all

char num[100]; double durationInMinutes;

/* Process the second part of the input */
while(scanf("%s\n", num) == 1) {      
   /* Get the number and convert it into std:: string */
   string numStr(num);
         
   /* If a "#" is encountered, exit */
   if(numStr == "#") {
      break;
   }
   /* Read the duraction in minutes */		
   scanf("%lf\n", &durationInMinutes);
   
   /* Process the rest of the input */
   ...
}
There really is nothing else crazy or weird going on in regards to the input.

(3) In regards to the output formatting, I used something like this

Code: Select all

printf("%-16s%-25s%10s%5.0lf%6.2lf%7.2lf\n", numberStr.c_str(), 
	    location.c_str(), 
	    subscriberNumberStr.c_str(), 
	    durationInMinutes,
	    pricePerMinute / 100.00,
	    pricePerMinute * durationInMinutes / 100.00);
Last, I've compiled a list test cases that I found useful during testing / debugging. They are on uDebug.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
anacharsis
Learning poster
Posts: 69
Joined: Mon Feb 09, 2015 1:56 am

Re: 139 - Telephone Tangles

Post by anacharsis »

OK, this one is driving me nuts.
I keep getting WA's and I can't tell if I'm getting closer.
Even more frustrating is that the reference solutions at UVA Toolkit and UDebug give different outputs for some inputs.

So, a few questions I'm hoping someone can answer:
1) Do we have to validate the IDD and STD codes in the initial input table? ( the stuff before 000000 )?
2) Is "00" a valid IDD code?
3) Do we have to check for non-digits in the code table and in the numbers that come in?

I've handled the non-tabular phone log case, and the spaces-in-location case.
I also did the formatting by column as they outlined in the problem statement.
Did the people that passed also do that?
Because in the UVA toolkit solution there is just a single space between the output call data

So, I'm at a loss as to figuring out what I'm doing wrong...
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 139 - Telephone Tangles

Post by brianfry713 »

Post your code.
Check input and AC output for thousands of problems on uDebug!
anacharsis
Learning poster
Posts: 69
Joined: Mon Feb 09, 2015 1:56 am

Re: 139 - Telephone Tangles

Post by anacharsis »

Code: Select all

AC'd
Last edited by anacharsis on Fri Feb 20, 2015 9:40 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 139 - Telephone Tangles

Post by brianfry713 »

Try running your code on the sample input. It should match the sample output.
Check input and AC output for thousands of problems on uDebug!
anacharsis
Learning poster
Posts: 69
Joined: Mon Feb 09, 2015 1:56 am

Re: 139 - Telephone Tangles

Post by anacharsis »

Wow, that was dumb of me.
I printed the IDD/STD prefix instead of the full number in the first column of the output, and then somehow didn't notice when I was comparing results.
Doh!

Thanks for the second pair of eyes!
Post Reply

Return to “Volume 1 (100-199)”