結果

問題 No.293 4>7の世界
ユーザー tentententen
提出日時 2020-10-07 09:38:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 3,675 ms
コンパイル使用メモリ 73,864 KB
実行使用メモリ 57,884 KB
最終ジャッジ日時 2023-09-27 09:08:50
合計ジャッジ時間 5,924 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
56,016 KB
testcase_01 AC 102 ms
56,000 KB
testcase_02 AC 103 ms
55,748 KB
testcase_03 AC 103 ms
55,724 KB
testcase_04 AC 101 ms
55,448 KB
testcase_05 AC 104 ms
55,660 KB
testcase_06 AC 109 ms
55,508 KB
testcase_07 AC 109 ms
55,960 KB
testcase_08 AC 106 ms
55,648 KB
testcase_09 AC 110 ms
55,652 KB
testcase_10 AC 112 ms
55,776 KB
testcase_11 AC 109 ms
55,868 KB
testcase_12 AC 104 ms
56,024 KB
testcase_13 AC 108 ms
57,884 KB
testcase_14 AC 109 ms
56,200 KB
testcase_15 AC 108 ms
55,796 KB
testcase_16 AC 106 ms
55,756 KB
testcase_17 AC 109 ms
56,000 KB
testcase_18 AC 110 ms
55,832 KB
testcase_19 AC 108 ms
55,428 KB
testcase_20 AC 109 ms
55,828 KB
testcase_21 AC 108 ms
56,060 KB
testcase_22 AC 108 ms
55,740 KB
testcase_23 AC 106 ms
55,720 KB
権限があれば一括ダウンロードができます

ソースコード

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