Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
帮忙看看哪里错了。总是runtime error。可能是第一个子函数有问题,但是没有找出来。#include <iostream.h> #include <stdio.h> #include <string.h> #include <math.h> #include <iomanip.h> char *Abbre[]={"UTC","GMT","BST","IST","WET","WEST","CET","CEST","EET", "EEST","MSK","MSD","AST","ADT","NST","NDT","EST","EDT", "CST","CDT","MST","MDT","PST","PDT","HST","AKST","AKDT", "AEST","AEDT","ACST","ACDT","AWST"}; float AbbTime[]={0,0,1,1,0,1,1,2,2,3,3,4,-4,-3,-3.5,-2.5,-5,-4,-6,-5,-7, -6,-8,-7,-10,-9,-8,10,11,9.5,10.5,8}; float AbbrToTime(char *Abbr) { int i=0; while(strcmp(Abbr,Abbre[i])) { i++; } return AbbTime[i]; } void ToTime24(char *Time12,char *apm,char *Time24) { int hour,minute; sscanf(Time12,"%d:%d",&hour,&minute); if(apm[0]!='\0') { if(!strcmp(apm,"a.m.")) if(hour!=12) strcpy(Time24,Time12); else sprintf(Time24,"%d:%d",0,minute); else { if(hour!=12) { hour=hour+12; sprintf(Time24,"%d:%d",hour,minute); } else sprintf(Time24,"%d:%d",12,minute); } } else if(!strcmp(Time12,"noon")) sprintf(Time24,"%d:%d",12,0); else sprintf(Time24,"%d:%d",0,0); } void ToTime12(char *Time24) { int hour,minute; sscanf(Time24,"%d:%d",&hour,&minute); if(hour==0 && minute==0) printf("midnight\n"); else if(hour==12 && minute==0) printf("noon\n"); else if(hour==0) cout<<12<<":"<<setw(2)<<setfill('0')<<minute<<" a.m."<<endl; else if(hour<12) cout<<hour<<":"<<setw(2)<<setfill('0')<<minute<<" a.m."<<endl; else if(hour==12) cout<<12<<":"<<setw(2)<<setfill('0')<<minute<<" p.m."<<endl; else cout<<hour-12<<":"<<setw(2)<<setfill('0')<<minute<<" a.m."<<endl; } void main() { int Hour,Minute; char Time[6],apm[5],From[5],To[5],Time24[6]; float TimeOfAbbre[2],Distance; int n; cin>>n; while(n--) { scanf("%s ",Time); if(strcmp(Time,"noon") && strcmp(Time,"midnight")) scanf("%s %s %s",apm,From,To); else { scanf("%s %s",From,To); apm[0]='\0'; } TimeOfAbbre[0]=AbbrToTime(From); TimeOfAbbre[1]=AbbrToTime(To); ToTime24(Time,apm,Time24); Distance=TimeOfAbbre[1]-TimeOfAbbre[0]; sscanf(Time24,"%d:%d",&Hour,&Minute); if(Distance==0) { if(strcmp(Time,"noon") && strcmp(Time,"midnight")) cout<<Time<<" "<<apm<<endl; else cout<<Time<<endl; } else if(Distance>0) { if(floor(Distance)==Distance) { Hour=Hour+Distance; if(Hour>=24) Hour=Hour-24; sprintf(Time24,"%d:%d",Hour,Minute); ToTime12(Time24); } else { Hour=Hour+floor(Distance); Minute=Minute+30; if(Minute>=60) { Minute=Minute-60; Hour=Hour+1; } if(Hour>=24) Hour=Hour-24; sprintf(Time24,"%d:%d",Hour,Minute); ToTime12(Time24); } } else { if(floor(Distance)==Distance) { Hour=Hour+Distance; if(Hour<0) Hour=Hour+24; sprintf(Time24,"%d:%d",Hour,Minute); ToTime12(Time24); } else { Hour=Hour+floor(Distance)+1; Minute=Minute-30; if(Minute<0) { Minute=Minute+60; Hour=Hour-1; } if(Hour<0) Hour=Hour+24; sprintf(Time24,"%d:%d",Hour,Minute); ToTime12(Time24); } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator