Page 5 of 5

Re: 139 help

Posted: Sun Jul 06, 2014 4:30 pm
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

Re: 139 - Telephone Tangles

Posted: Fri Sep 19, 2014 8:14 am
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.

Re: 139 - Telephone Tangles

Posted: Thu Feb 19, 2015 5:53 pm
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...

Re: 139 - Telephone Tangles

Posted: Thu Feb 19, 2015 9:51 pm
by brianfry713
Post your code.

Re: 139 - Telephone Tangles

Posted: Thu Feb 19, 2015 10:37 pm
by anacharsis

Code: Select all

AC'd

Re: 139 - Telephone Tangles

Posted: Fri Feb 20, 2015 9:19 pm
by brianfry713
Try running your code on the sample input. It should match the sample output.

Re: 139 - Telephone Tangles

Posted: Fri Feb 20, 2015 9:42 pm
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!