1 solutions

  • 0
    @ 2025-11-5 19:32:12

    C :

    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
    	int n, h1, h2, m1, m2, i, j, result;
    	int times[24][60];
    	
    	while (EOF != scanf("%d", &n)){
    		
    		memset(times, 0, sizeof (times));
    		while (n--){
    			
    			scanf("%d:%d %d:%d", &h1, &m1, &h2, &m2);
    			while (1){
    				times[h1][m1] = 1;
    				if (h1 == h2 && m1 == m2){
    					break;
    				}
    				m1++;
    				if (m1 == 60){
    					m1 = 0;
    					h1++;
    				}
    			}
    		}
    		
    		result = 0;
    		for (i = 0; i < 24; i++){
    			for (j = 0; j < 60; j++){
    				result += times[i][j];
    			}
    		}
    		
    		printf("%d\n", result);
    	}
    	
    	return 0;
    }
    
    

    C++ :

    
    /**
    崔成杰
    题目名称:用了多少水电费?
    题目描述:小明所在的宿舍,只要有人就必须开空调,真浪费。在无人道的物业下,空调每5分钟电费就要一毛钱。
    为了清楚知道自己宿舍一天开空调的总时间,小明做了一个时刻表,自动记录每个人在宿舍的时间:包括进入宿舍的时刻,离开宿舍的时刻。请你算出期间开空调的时间。
    
    输入描述:
    有多组数据。第一行有一个数字n,代表今天有n个人次进出宿舍
    接下来n行,每一行有一对表示时刻的数字,以24小时制表示 ,h1:m1  h2:m2 表示这个人当天进入宿舍的时间与离开宿舍的时间 。0<=h<=23  0<=m<=59
    
    输出描述:
    对于一组数据,输出一行
    当天宿舍开空调的总时间,用分钟表示。
    **/
    #include<iostream>
    #include<stdio.h>
    #include<string>
    #include<algorithm>
    #include<string.h>
    #include<set>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<limits.h>
    #include<math.h>
    #define FOR(i,a,b) for(int i=(a);i<(b);i++)
    #define FORD(i,a,b) for(int i=(a);i<=(b);i++)
    #define REP(i,b) FOR(i,0,b)
    #define CLR(a) memset(a,0,sizeof(a))
    using namespace std;
    #define maxn 200
    int main(){
    
        int n;
        while(~scanf("%d",&n)){
            int starth[maxn],startm[maxn],endh[maxn],endm[maxn];
            int time[1441];
            CLR(time);
            REP(i,n){
                scanf("%d:%d %d:%d",&starth[i],&startm[i],&endh[i],&endm[i]);
                int st=starth[i]*60+startm[i];
                int ed=endh[i]*60+endm[i];
                FORD(j,st,ed){
                    time[j]=1;
                }
            }
            int output=0;
            REP(i,1441){
                if(time[i]!=0)output++;
            }
            printf("%d\n",output);
        }
        return 0;
    }
    
    
    • 1

    Information

    ID
    19361
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By