PTA —— 基础编程题目集 —— 编程题 —— 7-2 然后是几点 (15 分)
生活随笔
收集整理的這篇文章主要介紹了
PTA —— 基础编程题目集 —— 编程题 —— 7-2 然后是几点 (15 分)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目
有時候人們用四位數字表示一個時間,比如1106表示11點零6分。
現在,你的程序要根據起始時間和流逝的時間計算出終止時間。
讀入兩個數字,
第一個數字以這樣的四位數字表示當前時間,
第二個數字表示分鐘數,
計算當前時間經過那么多分鐘后是幾點,結果也表示為四位數字。
當小時為個位數時,沒有前導的零,即5點30分表示為530。
注意,第二個數字表示的分鐘數可能超過60,也可能是負數。
輸入格式:
輸入在一行中給出2個整數,分別是四位數字表示的起始時間、以及流逝的分鐘數,其間以空格分隔。注意:在起始時間中,當小時為個位數時,沒有前導的零,即5點30分表示為530;流逝的分鐘數可能超過60,也可能是負數。
輸出格式:
輸出四位數字表示的終止時間。題目保證起始時間和終止時間在同一天內。
輸入樣例:
1120 110
輸出樣例:
1310
代碼
#include <stdio.h> int main (void) {int time1,time2;int hour1,hour2,hour3;int minute1,minute2,minute3;int a;printf("please enter a time (Use four digits to represent a time.):");scanf("%d",&time1);printf("Please input a number to indicate the time passed:");scanf("%d",&minute2);hour1=minute2/60;hour2=time1/100;hour3=hour1+hour2;minute1=time1%100;a = minute2;minute2=minute2-hour1*60;minute3=minute1+minute2;while(minute3>=60){hour3++;minute3-=60;}time2=hour3*100+minute3;printf("%d after %d minutes, it is %d",time1,a,time2);getchar();return 0; }總結
以上是生活随笔為你收集整理的PTA —— 基础编程题目集 —— 编程题 —— 7-2 然后是几点 (15 分)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PTA —— 基础编程题目集 —— 编程
- 下一篇: PTA —— 基础编程题目集 —— 编程