L1-043 Reading (20 minutes)

Reading Room L1-043 address the topic
Ladder reading room invite you to write a simple book lending statistics. When a reader library, enter the ISBN administrator and press the S key, the program start time; when the reader has the book, ISBN administrator input and press the E key, the program ends timing. ISBN no more than 1,000 positive integer. When the administrator ISBN 0 as input to indicate end of the day, your program should output the number of library readers and average reading time of the day.

Note: Due to occasional line fault, incomplete record may appear that not only S E, or E not only record S, the system should be able to automatically ignore this invalid record. In addition, to ensure that the title ISBN is a unique identifier of the book, the same book could only have been a reader to borrow at any time interval.
Input formats:

A first input line of a given positive integer N (≤10), followed by N days given record. Daily record of the number of times the operation consisting of borrowing, one row for each operation, in the format:

ISBN ([1, 1000] is an integer) key (S or E) occurrence time (hh: mm, where hh is an integer of [0,23] in, mm is [0, 59] within an integer)

Each day record of guarantee given in chronological order of increasing.
Output formats:

To record daily output day in a row library readers and average reading time (in minutes to the nearest integer bit of time).

This title is a liar that ah, the basic data processing.

1. see the library, it is conceivable to use the structure (a head).
2. title set to very bad
(1) borrow the same books, the last one meter
(2) is also the same book, namely, first, you need to have a flag array to determine whether the upper and lower borders.
(3) by the casual working to input and output, after 196 tests can determine the need for rounding (have a question, see a post before, into what a law is that the same effect?)
(4) structure (local variables) is cleared

#include<bits/stdc++.h>
struct o{
	int bo;
	int re;
	int time;
	int flag=0;
};

int main(void)
{
	int n;int flag=0,cnt=0,sum=0,book=1,hour,min;//其实这里也可以改成局部,但是我懒;
	char ch;
	scanf("%d",&n);
	while(n--)
	{
		struct o re[1050];//局部变量,循环后释放;
		do
		{
			scanf("%d %c %d:%d",&book,&ch,&hour,&min);
			if(book==0)break;
			else 
			{
				if(ch=='S') {
					re[book].flag=1;
					re[book].bo=hour*60+min;
				}
				else if(ch=='E'&&re[book].flag==1){
					cnt++;
					sum+=re[book].time=hour*60+min-re[book].bo;
					re[book].flag=0;
					
				}
			}
		}while(book!=0);
		if(cnt!=0)
		printf("%d %d\n",cnt,(int)(1.0*sum/cnt+0.5));
		else printf("0 0\n");
		cnt=0,sum=0,book=1;
	}
	
	return 0;
}

I'm back, after a lapse of several days, before engaging in a virtual machine and migration (not to brush the question, tears head), I wish you a happy New Year! (Handed him a red envelope stuffed with masks)

Published 10 original articles · won praise 4 · Views 269

Guess you like

Origin blog.csdn.net/dylan_sjc/article/details/104080110