SWEA 1976 시각 덧셈

1 개요[ | ]

SWEA 1976 시각 덧셈

2 C++[ | ]

#include <iostream>
using namespace std;
int T;
int h1, m1, h2, m2;
int main() {
	scanf("%d", &T);
	for(int tc=1; tc<=T; tc++) {
		scanf("%d %d %d %d", &h1, &m1, &h2, &m2);
		int h = h1 + h2;
		int m = m1 + m2;
		if(m>=60) {
			m -= 60;
			h++;
		}
		if(h>12) h -= 12;
		printf("#%d %d %d\n", tc, h, m);
	}
}

3 Java[ | ]

import java.util.Scanner;
public class Solution {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int t=1; t<=T; t++) {
            int h1 = sc.nextInt();
            int m1 = sc.nextInt();
            int h2 = sc.nextInt();
            int m2 = sc.nextInt();
            int h = h1 + h2;
            int m = m1 + m2;
            if( m > 60 ) {
                m -= 60;
                h++;
            }
            if( h > 12 ) h -= 12;
            System.out.format("#%d %d %d\n", t, h, m);
        }
    }
}

4 Python[ | ]

#kcy

k = int(input())

for i in range(1, k+1):
    n = list(map(int, input().split()))

    h = n[0] + n[2]
    m = n[1] + n[3]

    if m > 59:
        h = h + 1
        m = m -60
        
    if h > 12:
        h = h - 12

    print("#%d" %i, h, m)
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}