zoukankan      html  css  js  c++  java
  • Time Zone

    Time Zone

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2049    Accepted Submission(s): 636


    Problem Description
    Chiaki often participates in international competitive programming contests. The time zone becomes a big problem.
    Given a time in Beijing time (UTC +8), Chiaki would like to know the time in another time zone s.
     
    Input
    There are multiple test cases. The first line of input contains an integer T (1T106), indicating the number of test cases. For each test case:
    The first line contains two integers ab (0a23,0b59) and a string s in the format of "UTC+X'', "UTC-X'', "UTC+X.Y'', or "UTC-X.Y'' (0X,X.Y14,0Y9).
     
    Output
    For each test, output the time in the format of hh:mm (24-hour clock).
     
    Sample Input
    3
    11 11 UTC+8
    11 12 UTC+9
    11 23 UTC+0
     
    Sample Output
    11:11
    12:12
    03:23
     
    Source
     
     
    这题看起来不难,但是精度问题挺烦人的.
     
     1 #include <iostream>
     2 using namespace std;
     3 int n;
     4 int main(){
     5     scanf("%d",&n);
     6     int x,y;
     7     double z;
     8     char s[4];
     9     while(n--){
    10         scanf("%d%d%c%c%c%c%lf",&x,&y,&s[0],&s[1],&s[2],&s[3],&z);
    11         if(s[3]=='-'){
    12             z = -z;
    13         }
    14         double k = (z-8.0)*60.0;
    15         k += k>0?0.5:-0.5;
    16         int ans = (int)(k);
    17         ans +=(x*60+y);
    18         ans = (ans+1440)%1440;
    19         int xn = (ans/60)%24;
    20         int yn = ans%60;
    21         printf("%02d:%02d
    ",xn,yn);
    22     }
    23     return 0;
    24 }
     
     
  • 相关阅读:
    MYSQL语法篇之:“建”、“增”
    MYSQL数据库管理系统
    数据库管理系统
    初识数据库
    JDK/JRE/JVM的区别与联系
    计算机语言的发展史
    Java的三大版本
    Java的特性和优势
    初识Java
    补充:DOS命令
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/9364746.html
Copyright © 2011-2022 走看看