2018 Multi-University Training Contest 1 1011 标程学习

Time Zone

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

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 (1≤T≤106), indicating the number of test cases. For each test case:
The first line contains two integers a, b (0≤a≤23,0≤b≤59) and a string s in the format of "UTC+X'', "UTC-X'', "UTC+X.Y'', or "UTC-X.Y'' (0≤X,X.Y≤14,0≤Y≤9).

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

#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

int main() {
  std::ios::sync_with_stdio(false);
  int T;
  std::cin >> T;
  for (int cas = 1; cas <= T; ++cas) {
    int sgn;
    int a, b, x, y(0);
    std::string s;
    std::cin >> a >> b >> s;
    sgn = (s[3] == '+' ? 1 : -1);
    s = s.substr(4);
    /*
    假设:string s = "0123456789";
	string sub1 = s.substr(5); //只有一个数字5表示从下标为5开始一直到结尾:sub1 = "56789"
	string sub2 = s.substr(5, 3); //从下标为5开始截取长度为3位:sub2 = "567"
    */
    if (s.size() > 2) {
      y = s.back() - '0';
      s.pop_back();
      s.pop_back();
    }
    x = std::stoi(s);
    
    int m = (a + 24) * 60 + b;

    int c = 80;
    int d = sgn * (x * 10 + y);
    int e = d - c;
    int f = e * 6;
    int g = (m + f) % 1440;

    printf("%02d:%02d\n", g / 60, g % 60);
  }
  return 0;
}

猜你喜欢

转载自blog.csdn.net/blackmail3/article/details/81185672