Return to the Top of Page, First Page, or Novice Problem Set.
The small town of Petticoat Junction has hired you to help solve a problem that recently appeared. A while back the town of Petticoat Junction changed the speed limits at several locations. Since then, their sheriff and deputy have been constantly writing speeding tickets. Now they have so many tickets they need you to write a program to calculate the cost of the tickets.
The fine for speeding tickets in Petticoat Junction is calculated as follows:
Examples:
If the speed limit is 30 and the ticketed vehicle was traveling at 36 mph, the fine would be $35 + 6x$5, for a total of $65.
If the speed limit is 45 and the ticketed vehicle was traveling at 65 mph, the fine would be $35 + 14x$5 +6x$9, for a total of $159.
As you can see, speeding is a very expensive proposition in Petticoat Junction. Below are some samples from their data file with the ticket information. Each record has three numbers. The first number is the ticket number, the second number is the speed limit, and the third number is the clocked speed of the vehicle. You are to keep processing until you encounter ticket number -1.
Sample Input Data:
13975
30
36
14362
45
65
13977
65
101
-1
Sample Output:
Ticket # 13975 MPH over: 6 Fine: $65
Ticket # 13462 MPH over: 20 Fine: $159
Ticket # 13977 MPH over: 36 Fine: $303
Totals: 3 tickets for a total fine of $527
Spacing across the lines are not critical. Columns are not required to line up, but each line should have three distinct portions. A blank line must separate the last ticket from the totals line.
Return to the Top of Page, First Page, or Novice Problem Set.
Return to the Top of Page, First Page, or Novice Problem Set.
Source Code for a Solution to this Problem
// preprocessor directives #include <stdio.h> #define QUIT -1 int main(void) { int i,j,rem; int ticket, limit,fast,cost; int num_tickets =0, total_cost = 0; scanf("%d %d %d",&ticket,&limit,&fast); while(ticket != QUIT) { cost = 35; rem = fast - limit; if( rem <= 14) cost += rem *5; else cost += 14 *5 + (rem-14) * 9; total_cost += cost; num_tickets++; printf("Ticket # %5d MPH over: %4d Fine: $%5d.\n",ticket,rem,cost); scanf("%d %d %d", &ticket,&limit,&fast); } // while printf("\n\nTotals: %5d tickets for a total fine of $%d.\n",num_tickets, total_cost); return 0; } // main
Return to the Top of Page, First Page, or Novice Problem Set.
13975 30 36 14362 45 65 13977 65 101 -1
Return to the Top of Page, First Page, or Novice Problem Set.
Ticket # 13975 MPH over: 6 Fine: $ 65. Ticket # 14362 MPH over: 20 Fine: $ 159. Ticket # 13977 MPH over: 36 Fine: $ 303. Totals: 3 tickets for a total fine of $527.
Return to the Top of Page, First Page, or Novice Problem Set.
13975 30 36 14362 45 65 13977 65 101 12 40 41 47658 35 47 13978 70 71 17798 70 99 -1
Return to the Top of Page, First Page, or Novice Problem Set.
Ticket # 13975 MPH over: 6 Fine: $ 65. Ticket # 14362 MPH over: 20 Fine: $ 159. Ticket # 13977 MPH over: 36 Fine: $ 303. Ticket # 12 MPH over: 1 Fine: $ 40. Ticket # 47658 MPH over: 12 Fine: $ 95. Ticket # 13978 MPH over: 1 Fine: $ 40. Ticket # 17798 MPH over: 29 Fine: $ 240. Totals: 7 tickets for a total fine of $942.
Return to the Top of Page, First Page, or Novice Problem Set.
12345 10 20 12346 60 90 99999 120 210 55555 55 72 22222 210 330 98765 70 90 76543 25 40 34567 18 29 -1
Return to the Top of Page, First Page, or Novice Problem Set.
Ticket # 12345 MPH over: 10 Fine: $ 85. Ticket # 12346 MPH over: 30 Fine: $ 249. Ticket # 99999 MPH over: 90 Fine: $ 789. Ticket # 55555 MPH over: 17 Fine: $ 132. Ticket # 22222 MPH over: 120 Fine: $ 1059. Ticket # 98765 MPH over: 20 Fine: $ 159. Ticket # 76543 MPH over: 15 Fine: $ 114. Ticket # 34567 MPH over: 11 Fine: $ 90. Totals: 8 tickets for a total fine of $2677.
Return to the Top of Page, First Page, or Novice Problem Set.
Return to the LSU High School Programming Contest Homepage