欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

PAT基础编程题目-7-2 然后是几点

程序员文章站 2022-06-12 22:51:11
...

PAT基础编程题目-7-2 然后是几点

题目详情

PAT基础编程题目-7-2 然后是几点

题目地址:https://pintia.cn/problem-sets/14/problems/782

解答

大家可能会遇到题目给的测试能通过,但提交的时候总是不通过。我这里给两个特殊的关键测试点,供大家测试和理解题目。

  • 输入:1120 110 输出:1310
  • 输入:1000 -588 输出:12

C语言版

#include<stdio.h>
int main() {
	int minute, startTime, stopTime;
	int elapsed;  //流逝的
	scanf("%d %d", &startTime, &elapsed);
	minute = (startTime / 100) * 60 + startTime % 100;  //将开始时间化为分钟
	stopTime = minute + elapsed;
	stopTime = (stopTime / 60) * 100 + stopTime % 60;  // 再把分钟化为小时
	printf("%d", stopTime);
	return 0;
}

PAT基础编程题目-7-2 然后是几点

C++版

#include<iostream>
using namespace std;
int main() {
	int minute, startTime, stopTime, elapsed;
	cin >> startTime >> elapsed;
	minute = (startTime / 100) * 60 + startTime % 100;
	stopTime = minute + elapsed;
	stopTime = (stopTime / 60) * 100 + stopTime % 60;
	cout << stopTime;
	return 0;
}

PAT基础编程题目-7-2 然后是几点

Java版

import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		int startTime = 0,stopTime,elapsed = 0,minute;
		Scanner scanner = new Scanner(System.in);
		if(scanner.hasNext()) {
			startTime = scanner.nextInt();
			elapsed = scanner.nextInt();
		}
		scanner.close();
		minute = (startTime/100)*60+startTime%100;
		stopTime = minute+elapsed;
		stopTime = (stopTime/60)*100+stopTime%60;
		System.out.println(stopTime);
	}

}

PAT基础编程题目-7-2 然后是几点

创作不易,喜欢的话加个关注点个赞,谢谢谢谢谢谢!