许多人可能认为本期很难,不过我告诉你(并不难!)
题目:
描述
小慧不小心喝下了女巫调制的爱情药水,她每遇见一个人,就会爱上这个人;当她遇见下一个人时,又会爱上下一个人。
现在告诉你她遇见每个人的时间,请你求出她分别爱上了每个人多久。
输入
一个整数n(1<=n<=1000),接下来n行,分别是小慧遇见每个人的时间(24小时制,英文冒号)。
输出
一行一个整数,分别是小慧爱上每个人的时间。
样例输入1: 输出样例 1
4 4 hours 8:00 5 hours and 45 minutes 12:00 7 minutes 17:45 6 hours and 7 minut 17:52 废话不多说,直接上代码。可以用万能头文件。(详见下一期) #include <iostream> #ye using namespace std; class XH { public: int h1; char c1; int h2; }; int main() { int n; XH xh[1000]; cin>>n; for(int i = 0;i < n;i++) { cin>>xh[i].h1>>xh[i].c1>>xh[i].h2; } xh[n].h1=23; xh[n].c1=':'; xh[n].h2=59; for(int i = 0;i < n;i++) { if(xh[i+1].h2-xh[i].h2<0) { if(xh[i+1].h1-xh[i].h1-1>0&&xh[i+1].h2-xh[i].h2+60>0) cout<<xh[i+1].h1-xh[i].h1-1<<" hours and "<<xh[i+1].h2-xh[i].h2+60<<" minutes"<<endl; else if(xh[i+1].h1-xh[i].h1-1>0) cout<<xh[i+1].h1-xh[i].h1-1<<" hours"<<endl; else cout<<xh[i+1].h2-xh[i].h2+60<<" minutes"<<endl; } else { if(xh[i+1].h1-xh[i].h1>0&&xh[i+1].h2-xh[i].h2>0) cout<<xh[i+1].h1-xh[i].h1<<" hours and "<<xh[i+1].h2-xh[i].h2<<" minutes"<<endl; else if(xh[i+1].h1-xh[i].h1>0) cout<<xh[i+1].h1-xh[i].h1<<" hours"<<endl; else cout<<xh[i+1].h2-xh[i].h2<<" minutes"<<endl; } } return 0; }