Editorial
Algorithm Analysis
If the input number is negative, then we calculate its absolute value - this will not change the second digit. Next, we divide the number by until it is greater than . The last digit of the resulting number will be the second digit of the initial number.
Algorithm Implementation
Read the input number . Since it is a 64-bit number, we use the long long
type. If it is negative, then we change its sign to the opposite.
scanf("%lld",&n); if (n < 0) n = -n;
We divide the number by until it is greater than .
while (n > 99) n /= 10;
The last digit of the obtained number will be the second digit of the initial number. We print it.
res = n % 10; printf("%lld\n",res);
Java Implementation
import java.util.*; public class Main { public static void main(String []args) { Scanner con = new Scanner(System.in); long n = con.nextLong(); if (n < 0) n = -n; while (n > 99) n /= 10; long res = n % 10; System.out.println(res); con.close(); } }
Python Implementation
Read the input number .
n = int(input())
If the number is negative, then we change its sign to the opposite.
if n < 0: n = -n
We divide the number by until it is greater than .
while n > 99: n = n // 10
The last digit of the obtained number will be the second digit of the initial number. We print it.
res = n % 10 print(res)