BOJ 2908 상수

1 개요[ | ]

BOJ 2908 상수
  • 숫자를 뒤집어서 비교하는 문제
  • 알고리즘 분류: 문자열 처리

2 C++[ | ]

#include <iostream>
using namespace std;

int reverse(int num) {
    int digit100 = num/100;
    int digit1 = num % 10;
    return num - 100*digit100 - digit1 + 100*digit1 + digit100;
}

int main() {
    int a, b;
    cin >> a >> b;
    int c = reverse(a);
    int d = reverse(b);
    if( c > d ) {
        cout << c << '\n';
    } else {
        cout << d << '\n';
    }
}

3 Java[ | ]

import java.util.Scanner;
public class Main {
    private static int reverse(int num) {
        int a = num/100;
        int b = num%100/10;
        int c = num%10;
        return c*100 + b*10 + a;
    }
    public static void main(String args[]) {
        //System.out.println( reverse(734) ); // 437
        //System.out.println( reverse(893) ); // 398

        Scanner sc = new Scanner(System.in);
        int a = reverse(sc.nextInt());
        int b = reverse(sc.nextInt());
        
        int max;
        if( a > b ) max = a;
        else max = b;
        System.out.println(max);
    }
}

4 Perl[ | ]

($m, $n) = split / +/, <>;
$m = reverse $m;
$n = reverse $n;
printf("%s\n", ($m < $n ? $n : $m));

5 PHP[ | ]

<?php
$arr = explode(' ', strrev(rtrim(fgets(STDIN))));
echo max($arr);

6 Python[ | ]

print(max(input()[::-1].split()))
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}