結果

問題 No.293 4>7の世界
ユーザー tenten
提出日時 2020-10-07 09:38:02
言語 Java
(openjdk 23)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 3,953 ms
コンパイル使用メモリ 77,076 KB
実行使用メモリ 54,444 KB
最終ジャッジ日時 2024-07-20 03:16:13
合計ジャッジ時間 7,496 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		Num a = new Num(sc.next().toCharArray());
		Num b = new Num(sc.next().toCharArray());
		if (a.compareTo(b) > 0) {
		    System.out.println(a);
		} else {
		    System.out.println(b);
		}
	}
	
	static class Num implements Comparable<Num> {
	    char[] arr;
	    
	    public Num(char[] arr) {
	        this.arr = arr;
	    }
	    
	    public int compareTo(Num another) {
	        if (arr.length == another.arr.length) {
	            for (int i = 0; i < arr.length; i++) {
	                if (arr[i] == another.arr[i]) {
	                    continue;
	                }
	                if (arr[i] == '4' && another.arr[i] == '7') {
	                    return 1;
	                } else if (arr[i] == '7' && another.arr[i] == '4') {
	                    return -1;
	                } else {
	                    return arr[i] - another.arr[i];
	                }
	            }
	            return 0;
	        } else {
	            return arr.length - another.arr.length;
	        }
	    }
	    
	    public String toString() {
	        return new String(arr);
	    }
	}
}
0