zoukankan      html  css  js  c++  java
  • 时区间时间的转换

    //时区间时间的转换
    #include<stdio.h>
    #include<string.h>
    
    int difference(char *zone1,char *zone2)
    {
    	char zone[32][10]={"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 time[32]={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};
    	int i,j;
    	for(i=0;strcmp(zone[i],zone1);i++);
    	for(j=0;strcmp(zone[j],zone2);j++);
    	return (int)((time[i]-time[j])*60);
    }
    int main()
    {
    	int nCases,i;
    	scanf("%d",&nCases);
    	for(i=0;i<nCases;i++)
    	{
    		int hours,minute;
    		char time[9];
    		scanf("%s",time);		
    		switch(time[0])
    		{
    			case 'n':hours=12;
    					 minute=0;
    					 break;
    			case 'm':hours=0;
    					 minute=0;
    					 break;
    			default:sscanf(time,"%d:%d",&hours,&minute);
    					hours=hours%12;
    					scanf("%s",time);
    					if(time[0]=='p') hours+=12;
    		}
    		char timezone1[5],timezone2[5];
    		scanf("%s%s",timezone1,timezone2);
    		int newTime;
    		newTime=hours*60+minute+difference(timezone2,timezone1);
    		if(newTime<0) newTime+=1440;
    		newTime%=1440;
    		switch(newTime)
    		{
    			case 0:printf("midnight
    ");
    			break;
    			case 720:printf("noon
    ");
    			break;
    			default:
    				hours=newTime/60;
    				minute=newTime%60;
    				if(hours==0)
    					printf("12:%02d a.m.
    ",minute);
    				else if(hours<12)
    					printf("%d:%02d a.m.
    ",hours,minute);
    				else if(hours==12)
    					printf("12:%02d p.m.
    ",minute);
    				else
    					printf("%d:%02d p.m.
    ",hours%12,minute);
    		}
    	}
    	return 0;
    }

  • 相关阅读:
    蓝盾杯writeup
    记一次被吊打的排位赛(writeup)
    记一次简单的PHP代码审计(SSRF案例)
    记一次简单的GetShell案例
    斯坦福cs231n计算机视觉经典课程笔记(更新中)
    centos8 下配置 uwsgi + Django
    C++坑点随笔
    matlab调教日记 ---- 语法问题汇总
    matlab调教日记 --- debug篇
    MySQL解决中文编码问题
  • 原文地址:https://www.cnblogs.com/javafly/p/6037194.html
Copyright © 2011-2022 走看看