H. Reverse It!

Codeforces
IDCF72H
Time4000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
The 14th of March was the international day of mathematics, because of number π = 3.1415926... In the occasion of this day Goofy Nephews Unity Organization (GNU) wants to publish the fastest program in math at 1:59:26 AM. Now the time is 1:11:11 AM and the project team haven't checked their program yet. Because of shortage of time they want to check their program with some queries. So they hired Hormizd (one of the greatest programmers in world) to write a tester for GNU's new program. Because Hormizd has much more important things to do, he wants you to write a small part of tester and it is reversing the numbers. Help him before 1:59:26. We can reverse numbers easily. For example by reversing 1234 we get 4321. Note, that if the integer is negative then its reverse would be also negative. For example reverse of  - 123 is  - 321. Also, you have to delete all the leading zeroes before and after the reverse. Given an integer you have to help Hormizd reverse it. ## Input The first line contains a single integer _n_. It is less than 101000 by it's absolute value. This integer may have leading zeros. If it had leading zeros you should first omit them and print the reverse of remaining digits. It's guaranteed that input contains less than 10001 characters. ## Output Output a single integer, the reverse of the given number. You have to omit leading zeros in the output. [samples]
3月14日是国际数学日,因为数字 #cf_span[π = 3.1415926..]。 在这天,古怪侄子联盟(GNU)希望在凌晨1:59:26发布最快的数学程序。 现在时间是凌晨1:11:11,项目团队尚未检查他们的程序。由于时间紧迫,他们希望用一些查询来测试程序。因此,他们聘请了霍尔米兹德(世界上最伟大的程序员之一)为GNU的新程序编写测试器。由于霍尔米兹德有更重要的事情要做,他希望你帮他编写测试器的一小部分——即反转数字。请在1:59:26之前帮他完成。 我们可以轻松地反转数字。例如,反转 #cf_span[1234] 得到 #cf_span[4321]。 注意,如果整数为负数,则其反转结果也应为负数。例如,#cf_span[ - 123] 的反转是 #cf_span[ - 321]。 此外,你必须删除反转前后的所有前导零。 给定一个整数,你需要帮助霍尔米兹德将其反转。 第一行包含一个整数 #cf_span[n]。其绝对值小于 #cf_span[101000]。该整数可能包含前导零。如果存在前导零,你应该先去掉它们,然后反转剩余的数字。保证输入字符数少于10001个。 输出一个整数,即给定数字的反转结果。你必须在输出中省略前导零。 ## Input 第一行包含一个整数 #cf_span[n]。其绝对值小于 #cf_span[101000]。该整数可能包含前导零。如果存在前导零,你应该先去掉它们,然后反转剩余的数字。保证输入字符数少于10001个。 ## Output 输出一个整数,即给定数字的反转结果。你必须在输出中省略前导零。 [samples]
**Definitions** Let $ n \in \mathbb{Z} $ be the input integer, represented as a string of up to $ 10000 $ characters, possibly with leading zeros and a leading minus sign. Let $ s \in \{0,1\} $ denote the sign: - $ s = 1 $ if $ n < 0 $, - $ s = 0 $ if $ n \geq 0 $. Let $ d_1 d_2 \dots d_k $ be the string of decimal digits of $ |n| $, with leading zeros removed (i.e., the canonical decimal representation of $ |n| $). **Constraints** 1. $ |n| < 10^{1000} $ 2. The string representation of $ n $ has length $ \leq 10000 $ 3. The input may contain leading zeros, but the absolute value is non-zero (i.e., $ n \neq 0 $ is not explicitly guaranteed, but reversing zero is trivial). **Objective** Compute the reversed integer $ r $ as follows: 1. Strip leading zeros from $ |n| $ to obtain the digit string $ D = d_1 d_2 \dots d_k $, where $ d_1 \neq 0 $ (unless $ |n| = 0 $). 2. Reverse $ D $ to obtain $ D^R = d_k d_{k-1} \dots d_1 $. 3. Remove leading zeros from $ D^R $ to obtain $ D^R_{\text{trimmed}} $. 4. If $ D^R_{\text{trimmed}} $ is empty, set it to "0". 5. Apply the original sign: $$ r = \begin{cases} -\text{int}(D^R_{\text{trimmed}}) & \text{if } s = 1 \\ \text{int}(D^R_{\text{trimmed}}) & \text{if } s = 0 \end{cases} $$ Output $ r $ as an integer (i.e., without leading zeros or sign ambiguity).
Samples
Input #1
23
Output #1
32
Input #2
\-032
Output #2
\-23
Input #3
01234560
Output #3
654321
API Response (JSON)
{
  "problem": {
    "name": "H. Reverse It!",
    "description": {
      "content": "The 14th of March was the international day of mathematics, because of number π = 3.1415926... In the occasion of this day Goofy Nephews Unity Organization (GNU) wants to publish the fastest program ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF72H"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "The 14th of March was the international day of mathematics, because of number π = 3.1415926...\n\nIn the occasion of this day Goofy Nephews Unity Organization (GNU) wants to publish the fastest program ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "3月14日是国际数学日,因为数字 #cf_span[π = 3.1415926..]。\n\n在这天,古怪侄子联盟(GNU)希望在凌晨1:59:26发布最快的数学程序。\n\n现在时间是凌晨1:11:11,项目团队尚未检查他们的程序。由于时间紧迫,他们希望用一些查询来测试程序。因此,他们聘请了霍尔米兹德(世界上最伟大的程序员之一)为GNU的新程序编写测试器。由于霍尔米兹德有更重要的事情要做,他希望你帮他编...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the input integer, represented as a string of up to $ 10000 $ characters, possibly with leading zeros and a leading minus sign.\n\nLet $ s \\in \\{0,1\\} $ den...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments