First or last?#903

First or last? (Editorial)

From the three-digit number , we extract the hundreds and units digits: a = n / 100, c = n \% 10. Then, we output the answer using a conditional statement.

Algorithm Implementation

Read the three-digit number . Extract the hundreds digit and the units digit .

scanf("%d", &n);
a = n / 100; b = n % 10;

If a = c, then we output the equality sign. Otherwise, we compare and and output the larger digit.

if (a == b) printf("=\n"); else
if (a > b) printf("%d\n", a); else
printf("%d\n", b);

Java Implementation

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner con = new Scanner(System.in);
        int n = con.nextInt();
        int a = n / 100;
        int b = n % 10;
        
        if (a == b) System.out.println("=");
        else if (a > b) System.out.println(a);
        else System.out.println(b);
        
        con.close();
    }
}

Java Implementation – Strings

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner con = new Scanner(System.in);
        String s = con.next();
        
        int a = s.charAt(s.length()-1) - '0';
        int b = s.charAt(0) - '0';
        
        if (a == b) System.out.println("=");
        else if (a > b) System.out.println(a);
        else System.out.println(b);
        
        con.close();
    }
}

Python Implementation

n = int(input())
a = n // 100
b = n % 10

if a == b: print("=")
elif a > b: print(a)
else: print(b)