文章

84

粉丝

408

获赞

33

访问

871.9k

头像
偷菜时间表(c++)
P1053
发布于2020年7月13日 09:55
阅读数 10.6k

输入采用scanf("%d:%d", &time.hour, &time.minute)会比较省事 

#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
typedef struct Node{
	int hour;
	int minute;
	int endh;
	int endm;
}node;
int main()
{
	int N;
	cin >> N;
	int starth = 13, startm = 15;
	vector<node> vtime;
	for (int i = 0; i < N; i++) {
		node time;
		scanf("%d:%d", &time.hour, &time.minute);
		int carry = 0;
		time.endm = startm + time.minute;
		if (time.endm >= 60) {
			carry = 1;
			time.endm -= 60;
		}
		time.endh = (starth + time.hour + carry) % 24;
		vtime.push_back(time);
	}
	for (int i = 0; i < N; i++) {
		cout << vtime[i].endh << ":" << vtime[i].endm << endl;
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

1 条评论
wangkongqiang
2021年1月16日 22:18

#include<bits/stdc++.h>
using namespace std;
typedef struct Node{
    int hour;
    int minute;
    int endh;
    int endm;
}node;
int main()
{
    int N;
    cin>>N;
    int starth=13,startm=15;
    vector<node> vtime;
    for(int i=0;i<N;i++)
    {
        node time;
        scanf("%d:%d",&time.hour,&time.minute);
        int carry=0;
        time.endm=startm+time.minute;
        if(time.endm>=60)
        {
            carry=1;
            time.endm-=60;
        }
        time.endh=(starth+time.hour+carry)%24;
        vtime.push_back(time);
    }
    for(int i=0;i<N;i++)
    {
        cout<<vtime[i].endh<<":"<<vtime[i].endm<<endl;
    }
    return 0;
}
 

赞(0)