Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

高手给看下吧!测试数据都没问题,WA了N次了!!!!

Posted by 1234_ at 2007-03-10 16:04:44 on Problem 2351
#include<stdio.h>
#include<string.h>
char abbre[32][5]={"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};
int main()
{
	int n;
	char c;
	scanf("%d",&n);
	c=getchar();
	while(n--)
	{
		char tmp[25],zone1[5],zone2[5],area[10]={'\0'};
		int hour,min,i,num1,num2;
		gets(tmp);
		switch(tmp[0])
		{
		case 'n':hour=12;min=0;sscanf(tmp,"%s %s %s",area,zone1,zone2);
			break;
		case 'm':hour=0;min=0;sscanf(tmp,"%s %s %s",area,zone1,zone2);
			break;
		default:sscanf(tmp,"%d:%d %s %s %s",&hour,&min,area,zone1,zone2);
			break;
		}
		if(strcmp(area,"p.m.")==0&&hour!=12)
			hour+=12;
		if(strcmp(area,"a.m.")==0&&hour==12)
			hour=0;
		min+=hour*60;
		for(i=0;i<32;i++)
		{
			if(strcmp(zone1,abbre[i])==0)
			{
				num1=i;
				break;
			}
		}
		min-=(int)abbtime[num1]*60;
		for(i=0;i<32;i++)
		{
			if(strcmp(zone2,abbre[i])==0)
			{
				num2=i;
				break;
			}
		}
		min+=(int)abbtime[num2]*60;
	    if(min>=0)
		{
			hour=min/60;
			min-=hour*60;
			while(hour>=24)
				hour-=24;
		}
		else if(min<0)
		{
			min+=24*60;
			hour=min/60;
			min-=hour*60;
		}
		if(hour>12)
		{
			printf("%d:%02d p.m.\n",hour-12,min);
		}
		else if(hour<12&&hour!=0&&!(hour==0&&min==0))
		{
			printf("%d:%02d a.m.\n",hour,min);
		}
		else if(min==0&&hour==0)
		{
			printf("midnight\n");
		}
		else if(hour==0)
		{
			printf("%d:%02d a.m.\n",hour+12,min);
		}
		else if(hour==12&&min==0)
		{
			printf("noon\n");
		}
		else if(hour==12&&min!=0)
		{
			printf("%d:%02d p.m.\n",hour,min);
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator