題意:
題目開頭先給你時區的簡稱,Input :time 時區1 時區2
Output:將在時區1的time 換算成在時區2的time 並輸出
胡言亂語:
這題,卡在12小時制時間的換算超久QAQ
而函式的用法和#uva 860差不多XD
可以點進去看就好,先附上debug兩天...的程式碼~~~
...最後竟然是我把720打成780....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<cstring> | |
#include<cstdio> | |
#include<cstdlib> | |
#include<iomanip> | |
#include<map> | |
using namespace std; | |
map <string,double> table; | |
void init(){ | |
table["UTC"] = 0 , table["GMT"] = 0; | |
table["BST"] = 1 , table["IST"] = 1; | |
table["WET"] = 0 , table["WEST"] = 1; | |
table["CET"] = 1 , table["CEST"] = 2; | |
table["EET"] = 2 , table["EEST"] = 3; | |
table["MSK"] = 3 , table["MSD"] = 4; | |
table["AST"] = -4 , table["ADT"] = -3; | |
table["NST"] = -3.5 , table["NDT"] = -2.5; | |
table["EST"] = -5, table["EDT"] = -4; | |
table["CST"] = -6, table["CDT"] = -5; | |
table["MST"] = -7, table["MDT"] = -6; | |
table["PST"] = -8, table["PDT"] = -7; | |
table["HST"] = -10, table["AKST"] = -9; | |
table["AKDT"] = -8 , table["AEST"] = 10; | |
table["AEDT"] = 11 , table["ACST"] = 9.5; | |
table["ACDT"] = 10.5 , table["AWST"] = 8; | |
} | |
int main(){ | |
init();//建表 | |
int N,time,short_hand,long_hand;//時針、分針 | |
string st,local,outside;//a.m/p.m、當地時間、外地時間 | |
int tag; | |
scanf("%d",&N);//讀入有幾筆測資 | |
cin.get();//讀掉換行字元 | |
while(N--){ | |
tag = 0; | |
char *p, str1[100] ; | |
cin.getline(str1,100); | |
p = strtok(str1, " :"); | |
while (p != NULL) { | |
tag++; | |
if(tag==1){ | |
if(isdigit(*p)) short_hand = atof(p); | |
else { | |
tag = 3; | |
if(!strcmp(p,"noon")) time = 12*60; | |
if(!strcmp(p,"midnight")) time = 0; | |
} | |
} | |
else if(tag==2) long_hand = atof(p); | |
else if(tag==3) { | |
time = long_hand+ short_hand*60; | |
if(time>=720&&time<780) time-=720; | |
if(!strcmp(p,"p.m.")) { | |
time+=720; | |
} | |
} | |
else if(tag==4) local = p; | |
else if(tag==5) outside = p; | |
p = strtok(NULL, " :"); | |
} | |
time =time+ (table[outside]-table[local])*60+24*60; | |
time %=1440;//因為time可能為負 | |
short_hand = (time/60)%24; | |
long_hand = time%60; | |
//printf("%d ",time); | |
if(time == 0) | |
printf("midnight\n"); | |
else if(time == 720) | |
printf("noon\n"); | |
else{ | |
cout<<(time/60%12?time/60%12:12)<<":"<<setw(2)<<setfill('0')<<(time%60)<<" "; | |
cout<<(time>720?"p.m.":"a.m.")<<endl; | |
} | |
} | |
} |