@@ -35,22 +35,24 @@ bool can(double f) {
3535
3636int main () {
3737 int n;
38+ char line[100 ];
3839 while (scanf (" 0 Fuel consumption %d\n " , &n), n) {
3940 events.clear ();
4041 events.emplace_back (0 , -n); // first event
4142 while (1 ) {
42- int d; char line[100 ]; scanf (" %d " , &d); gets (line);
43+ memset (line, 0 , 100 );
44+ int d; scanf (" %d " , &d); fgets (line, 99 , stdin);
4345 if (strncmp (line, " Fuel" , 4 ) == 0 ) { // the first four characters are "Fuel"
4446 sscanf (line, " Fuel consumption %d" , &n);
4547 events.emplace_back (d, -n);
4648 }
47- else if (strcmp (line, " Leak" ) == 0 )
49+ else if (strcmp (line, " Leak\n " ) == 0 )
4850 events.emplace_back (d, 1 );
49- else if (strcmp (line, " Gas station" ) == 0 )
51+ else if (strcmp (line, " Gas station\n " ) == 0 )
5052 events.emplace_back (d, 2 );
51- else if (strcmp (line, " Mechanic" ) == 0 )
53+ else if (strcmp (line, " Mechanic\n " ) == 0 )
5254 events.emplace_back (d, 3 );
53- else if (strcmp (line, " Goal" ) == 0 ) {
55+ else if (strcmp (line, " Goal\n " ) == 0 ) {
5456 events.emplace_back (d, 4 );
5557 break ;
5658 }
0 commit comments