Home > Back-end >  Turn a problem encountered problems in PTA seek help from god
Turn a problem encountered problems in PTA seek help from god

Time:09-30

7-9 reading room (20 points)

Ladder library would you please write a simple library statistical procedure, when readers borrow books, the administrator input and press the S key, the number of program timing starts; When readers also book, administrators and press the E key, the number of input end of the program timing, for no more than 1000 the number of positive integers, when the administrator will be 0 as the input, the number of said the end of a day's work, on the day of your program should output the number of readers borrow books and the average reading time,

Note: due to occasional fault, incomplete records may occur, which not only S E, or only E no S records, the system shall be able to ignore the invalid records automatically, in addition, the title guarantee is the unique identification of the book, the number of the same book at any time interval can be only one reader borrows,
Input format:

Input in the first row is given a positive integer N (10) or less, then give N days record, record which is made up of several lending operations every day, every time a line operation, format for:

Book number (integer) in [1, 1000] are the key value (S) or E time (hh: mm, with hh is integer [0, 10], mm is [0, 59] integer)

Every day record to ensure that increasing according to time sequence is given,
The output format:

To record every day, in a line of the output number readers borrow books and the average reading time of day (in the precision of minutes for the unit to bits of the integer),
Input the sample:

3
1 S 08:10
2 S 08:35
1 E 10:00
2 E:

0 S 17:00
0 S 17:003 E 08:10
1 S 08:20
2 S 09:00
1 E 09:20

0 E 17:00





The output sample:

2 196
0 0
1 60//


This is a topic and then I write the code as follows
#include
#include
#include
Int main ()
{float minute (int p, int q, int x, int y);//define functions
Int day;
Char t [50] [2];//serial number
Int l [50] [2];//time
Float w=0;//number of readers
Int o, ok=1;//tag
Float k=0; Float c;
The scanf (" % d ", & amp; Day); Int ii=0; int i=0;
For (ii=0; Ii{ok=1; Reset//tag
Memset (t, 0, sizeof (t)); Memset (l, 0, sizeof (l));//array to empty
While (ok) {
The scanf (" % c % c % d: % d ", & amp; T [I] [0], & amp; T [1], [I] & amp; L [I] [0], & amp; L [I] [1]);//input a set of data
If (t [0] [I]!=48)//whether the first zero
{the for (o=I; O>=0; O -)
{if (t [I] [0]==t [o] [0] & amp; & T [I] [1]=='E' & amp; & T [o] [1]=='S')//looking for historical data, determine whether accord with the first and second E or S, respectively, if has the next step operation, otherwise continue to look for historical data
{k=k + minute (l [I] [0], l [I] [1], [o] l [0], l [o] [1]). W=w + 1; }};//and the number of readers and reading time
I=I + 1; }//array gal.
The else {
If (w==0) {//whether readers number is 0, if directly 0, if not the operations
Printf (" 0 0 \ n "); }
The else {c=round (k/w);
Printf (" %. 0 f %. 0 f \ n ", w, c); }
W=0; K=0; Ok=0; }}//data reset, jump out of the loop
}
return 0;
}

Float minute (int p, int q, int x, int y)
{float min;
Min=(p - x) * 60 + - y (q);//conversion time
Return min;
}
//
He gave the data input is correct but the PTA testing after only a set of answer shows two groups right answer and a set of errors is really don't understand the great god for help

CodePudding user response:

 # include 
#include
#include

Float minute (int p, int q, int x, int y);//define functions
Int main ()
{
Int day;
Char t [50] [2];//serial number
Int l [50] [2];//time
Float w=0;//number of readers
Int o, ok=1;//tag
Float k=0; Float c;
The scanf (" % d ", & amp; Day);
Int ii=0; int i=0;
For (ii=0; Ii{
Ok=1; Reset//tag
Memset (t, 0, sizeof (t)); Memset (l, 0, sizeof (l));//array to empty
While (ok) {
The scanf (" % c % c % d: % d ", & amp; T [I] [0], & amp; T [1], [I] & amp; L [I] [0], & amp; L [I] [1]);//input a set of data
If (t [0] [I]!=48)//whether the first zero
{
For (o=I; O>=0; O -)
{
If (t [I] [0]==t [o] [0] & amp; & T [I] [1]=='E' & amp; & T [o] [1]=='S')//looking for historical data, determine whether accord with the first and second E or S, respectively, if has the next step operation, otherwise continue to look for historical data
{
K=k + minute (l [I] [0], l [I] [1], [o] l [0], l [o] [1]).
W=w + 1;
}
};//and the number of readers and reading time//here why add; The semicolon
I=I + 1;
}//array gal.
The else {
If (w==0) {//whether readers number is 0, if directly 0, if not the operations
Printf (" 0 0 \ n ");
}
The else {
//c=round (k/w);//round for double roundf () for float
C=roundf (k/w);
Printf (" %. 0 f %. 0 f \ n ", w, c);
}
W=0; K=0; Ok=0;
}
}//data reset, jump out of the loop
}
return 0;
}

Float minute (int p, int q, int x, int y)
{
The float min;
Min=(p - x) * 60 + - y (q);//conversion time
Return min;
}


For your reference ~

Doubt is the problem that round, but not sure.

Code style of the building Lord really is very unique, however, the code is not long but looking at trouble, you don't have the feel?

CodePudding user response:

The
reference 1/f, confident boy reply:
 # include 
#include
#include

Float minute (int p, int q, int x, int y);//define functions
Int main ()
{
Int day;
Char t [50] [2];//serial number
Int l [50] [2];//time
Float w=0;//number of readers
Int o, ok=1;//tag
Float k=0; Float c;
The scanf (" % d ", & amp; Day);
Int ii=0; int i=0;
For (ii=0; Ii{
Ok=1; Reset//tag
Memset (t, 0, sizeof (t)); Memset (l, 0, sizeof (l));//array to empty
While (ok) {
The scanf (" % c % c % d: % d ", & amp; T [I] [0], & amp; T [1], [I] & amp; L [I] [0], & amp; L [I] [1]);//input a set of data
If (t [0] [I]!=48)//whether the first zero
{
For (o=I; O>=0; O -)
{
If (t [I] [0]==t [o] [0] & amp; & T [I] [1]=='E' & amp; & T [o] [1]=='S')//looking for historical data, determine whether accord with the first and second E or S, respectively, if has the next step operation, otherwise continue to look for historical data
{
K=k + minute (l [I] [0], l [I] [1], [o] l [0], l [o] [1]).
W=w + 1;
}
};//and the number of readers and reading time//here why add; The semicolon
I=I + 1;
}//array gal.
The else {
If (w==0) {//whether readers number is 0, if directly 0, if not the operations
Printf (" 0 0 \ n ");
}
The else {
//c=round (k/w);//round for double roundf () for float
C=roundf (k/w);
Printf (" %. 0 f %. 0 f \ n ", w, c);
}
W=0; K=0; Ok=0;
}
}//data reset, jump out of the loop
}
return 0;
}

Float minute (int p, int q, int x, int y)
{
The float min;
Min=(p - x) * 60 + - y (q);//conversion time
Return min; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related