3 条题解

  • 1
    @ 2021-04-23 20:40:28
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        int h,m,s; cin>>h>>m>>s;
        int pasttime; cin>>pasttime;
        while(pasttime){
            pasttime--;
            s++;
            if(s>59){
                s=0;
                m++;
            }
            if(m>59){
                h++;
                m=0;
            }
            if(h>23)
                h=0;
        }
        cout<<h<<" "<<m<<" "<<s;
        return 0;
    } 
    
  • 1
    @ 2019-03-31 13:20:38
    #include <iostream>
    using namespace std;
    class Time
    {
        int hour;
        int minute;
        int second;
    public:
        void init(int h, int m, int s)
        {
            hour = h;
            minute = m;
            second = s;
        }
        void add(int num)
        {
            second = second + num;
            if (second >= 60)
            {
                minute += second / 60;
                second = second % 60;
            }
                
            if (minute >= 60)
            {
                hour += minute / 60;
                minute = minute % 60;
            }
            if (hour >= 24)
            {
                hour = hour % 24;
            }
        }
        void print()
        {
            cout << hour << " " << minute << " " << second;
        }
    };
    int main()
    {
        int h, m, s;
        cin >> h >> m >> s;
        int num;
        cin >> num;
        Time time;
        time.init(h, m, s);
        time.add(num);
        time.print();
    
        return 0;
    }
    
  • -1
    @ 2020-10-02 16:38:33
    import java.io.IOException;
    import java.util.Scanner;
    
    public class Main {
    
        public static void main(String[] args) throws IOException{
            Scanner sc = new Scanner(System.in);
            String ont_line = sc.nextLine();
            String tow_line = sc.nextLine();
            String[] strIn = ont_line.trim().split(" ");
            Time time = new Time(Integer.valueOf(strIn[0]),Integer.valueOf(strIn[1]),Integer.valueOf(strIn[2]));
            time.add(Integer.valueOf(tow_line));
            time.printTime();
        }
    }
    class Time{
        private Integer hour;
        private Integer minute;
        private Integer second;
        public Time(Integer hour,Integer minute,Integer second){
            this.hour = hour;
            this.minute = minute;
            this.second = second;
        }
    
        public void add(Integer num){
            this.second = this.second + num;
            if(this.second >= 60){
                this.minute = this.minute + this.second / 60;
                this.second = this.second % 60;
            }
    
            if(this.minute >= 60){
                this.hour = this.hour + this.minute / 60;
                this.minute = this.minute % 60;
            }
    
            if(this.hour >= 24){
                this.hour = this.hour % 24;
            }
        }
    
        public void printTime(){
            System.out.println(this.hour+" "+this.minute+" "+this.second);
        }
    }
    
    
    
  • 1

信息

ID
1000
难度
7
分类
(无)
标签
递交数
1394
已通过
243
通过率
17%
被复制
6
上传者