7-1 时间换算 (10分)
程序员文章站
2024-02-27 13:45:33
...
知识点:
1.输入格式:0:0:1 cin>>a>>ch>>b>>ch>>c;
2.时间换算:
c=c+n;
while(c>=60){
b++;
c=c-60;
}
while(b>=60){
a++;
b=b-60;
}
if(a >= 24){
a = a - 24;
}
代码
#include<iostream>
using namespace std;
int main(){
int repeat; cin>>repeat;
for(int i=0;i<repeat;i++){
int a,b,c,n; char ch;
cin>>a>>ch>>b>>ch>>c;
cin>>n;
c=c+n;
while(c>=60){
b++;
c=c-60;
}
while(b>=60){
a++;
b=b-60;
}
if(a >= 24){
a = a - 24;
}
cout<<"time: "<<a<<':'<<b<<':'<<c<<endl;
}
}