// Longest Nap.cpp : Defines the entry point for the console application. // #include "stdafx.h" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { void CalTime(char **a,int *b,int c,int d); int testround=0;// save the test data time; int round=0; while(cin>>testround) { ++round; cin.ignore(); char **plan=new char*[testround];//save the plan of the doctor; int *naptime=new int[testround+1]; for(int create1=0; create1<testround;++create1) { plan[create1]=new char[255]; for(int create2=0;create2<255;++create2)plan[create1][create2]='/0'; } for(int x=0;x<testround;++x)cin.getline(plan[x],255); CalTime(plan,naptime,testround,round); for(int recover=0;recover<testround;++recover)delete plan[recover]; delete []plan; delete []naptime; } system("pause"); return 0; } void CalTime(char **a,int *b,int c,int d) { int result=0; int maxindex=0; int hom=0; for(int i=0;i<c+1;++i) { if(i==0)b[i]=((a[i][0]-48)*10+(a[i][1]-48))*60+(a[i][3]-48)*10+(a[i][4]-48)-60*10; else if(i==c)b[i]=18*60-(((a[i-1][6]-48)*10+(a[i-1][7]-48))*60+(a[i-1][9]-48)*10+(a[i-1][10]-48)); else { b[i]=(((a[i][0]-48)*10+(a[i][1]-48))*60+(a[i][3]-48)*10+(a[i][4]-48))-(((a[i-1][6]-48)*10+(a[i-1][7]-48))*60+(a[i-1][9]-48)*10+(a[i-1][10]-48)); } } for(int x=1;x<c+1;++x) { if(b[x]>b[maxindex])maxindex=x; } if(maxindex==0) { if((b[maxindex]%60==0)&&(b[maxindex]/60!=0)) { result=b[maxindex]/60; cout<<"Day #"<<d<<"the longest nap starts at 10:00 and will last for "<<result<<" hours."<<"/n"; } else if((b[maxindex]/60==0)&&(b[maxindex]%60!=0)) { result=b[maxindex]%60; cout<<"Day #"<<d<<"the longest nap starts at 10:00 and will last for "<<result<<" minutes."<<"/n"; } else if((b[maxindex]/60!=0)&&(b[maxindex]%60!=0)) { result=b[maxindex]/60; cout<<"Day #"<<d<<"the longest nap starts at 10:00 and will last for "<<result<<" hours and "; result=b[maxindex]%60; cout<<result<<" minutes."<<"/n"; } } else { if((b[maxindex]%60==0)&&(b[maxindex]/60!=0)) { result=b[maxindex]/60; cout<<"Day #"<<d<<"the longest nap starts at "<<a[maxindex-1][6]<<a[maxindex-1][7]<<a[maxindex-1][8] <<a[maxindex-1][9]<<a[maxindex-1][10]<<" and will last for "<<result<<" hours."<<"/n"; } else if((b[maxindex]/60==0)&&(b[maxindex]%60!=0)) { result=b[maxindex]%60; cout<<"Day #"<<d<<"the longest nap starts at "<<a[maxindex-1][6]<<a[maxindex-1][7]<<a[maxindex-1][8] <<a[maxindex-1][9]<<a[maxindex-1][10]<<" and will last for "<<result<<" minutes."<<"/n"; } else if((b[maxindex]/60!=0)&&(b[maxindex]%60!=0)) { result=b[maxindex]/60; cout<<"Day #"<<d<<"the longest nap starts at "<<a[maxindex-1][6]<<a[maxindex-1][7]<<a[maxindex-1][8] <<a[maxindex-1][9]<<a[maxindex-1][10]<<" and will last for "<<result<<" hours and "; result=b[maxindex]%60; cout<<result<<" minutes."<<"/n"; } } }