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
or
(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.