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,无语了

Posted by ycode at 2010-04-15 23:11:16 on Problem 2351
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int differences(char *zone1, char *zone2){
    char *zone[32] = {
         "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 ++){
            char time[9];
            int hours, minutes;
            scanf("%s" , time);
            switch(time[0]){
                            case 'n':
                                 hours = 12; 
                                 minutes = 0;
                                 break;
                            case 'm':
                                 hours = 0;
                                 minutes = 0;
                                 break;
                            default:
                                    sscanf(time, "%d:%d", &hours, &minutes);
                                    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 + minutes + differences(timezone2, timezone1);
            if(newTime < 0) newTime += 1440;
            newTime %= 1440;
            switch(newTime){
                   case 0:
                        printf("midnight\n");
                        break;
                   case 720:
                        printf("noon\n");
                        break;
                   default:
                           hours = newTime / 60;
                           minutes = newTime % 60;
                           if(hours == 0)
                             printf("12:%02d a.m.\n",minutes);
                           else if(hours < 12)
                             printf("%d:%02d a.m.\n", hours, minutes);
                           else if(hours == 12)
                             printf("12:%02d a.m.\n",minutes);
                           else printf("%d:%02d p.m.\n", hours % 12, minutes);
                   }
            }
    system("pause");
    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