当前位置: 代码迷 >> 综合 >> HDU6308 Time Zone(字符串)
  详细解决方案

HDU6308 Time Zone(字符串)

热度:62   发布时间:2023-11-08 16:14:09.0

题意:时区划分,东八区作为标准,给定其他地区的时区,输出当地的时间。
分析:

WA了。。。

#include<bits/stdc++.h>
#define maxn 100010
using namespace std;
int N,xx,yy;
typedef struct Node{int sta,ed;char ss[10];
}node;
node A[maxn];
int ans,ans1;
void print(int xx,int yy){while(xx<0||yy<0){if(xx<0) xx+=24;if(yy<0) {yy+=60;xx--;}}if(xx<10&&yy<10) cout<<"0"<<xx<<":"<<"0"<<yy<<endl;else if(xx<10&&yy>10) cout<<"0"<<xx<<":"<<yy<<endl;else if(xx>10&&yy<10) cout<<xx<<":"<<"0"<<yy<<endl;else cout<<xx<<":"<<yy<<endl;
}
//UTC+9
void solve1(int i){if(A[i].ss[3]=='+'){ans=int(A[i].ss[4]-'0')-8;}else {ans=-1*int(A[i].ss[4]-'0')-8;}
}
//UTC+10
void solve2(int i){if(A[i].ss[3]=='+'){ans=10*int(A[i].ss[4]-'0')+int(A[i].ss[5]-'0')-8;}else {ans=-1*int(A[i].ss[4]-'0'+int(A[i].ss[5]-'0'))-8;}
}
//UTC+9.5
void solve3(int i){if(A[i].ss[3]=='+'){ans=int(A[i].ss[4]-'0')-8;ans1=int(A[i].ss[6]-'0');}else {ans=-1*int(A[i].ss[4]-'0')-8;ans1=-1*int(A[i].ss[6]-'0');}
}
//UTC+10.5
void solve4(int i){if(A[i].ss[3]=='+'){ans=int(A[i].ss[4]-'0');ans=ans*10+int(A[i].ss[5]-'0')-8;ans1=int(A[i].ss[7]-'0');}else {ans=int(A[i].ss[4]-'0');ans=-1*(ans*10+int(A[i].ss[5]-'0'))-8;ans1=-1*int(A[i].ss[7]-'0');}
}int main(){scanf("%d",&N);for(int i=0;i<N;i++){ans=0;ans1=0;scanf("%d%d",&A[i].sta,&A[i].ed);scanf("%s",A[i].ss);int len=strlen(A[i].ss);if(len==5){         //UTC+9solve1(i);}else if(len==6){    //UTC+10solve2(i);}else if(len==7){    //UTC+9.5solve3(i);}else {              //UTC+10.5solve4(i);}// cout<<"ans="<<ans<<"ans1="<<ans1<<endl;ans=ans*60+ans1*0.1*60;xx=A[i].sta+ans/60;yy=A[i].ed+ans%60;print(xx,yy);}return 0;
}
  相关解决方案