結果

問題 No.293 4>7の世界
ユーザー kenji_shioyakenji_shioya
提出日時 2016-06-14 06:14:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 1,608 bytes
コンパイル時間 4,156 ms
コンパイル使用メモリ 74,736 KB
実行使用メモリ 56,268 KB
最終ジャッジ日時 2023-08-28 22:11:03
合計ジャッジ時間 8,063 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,048 KB
testcase_01 AC 120 ms
55,820 KB
testcase_02 AC 120 ms
55,872 KB
testcase_03 AC 119 ms
56,268 KB
testcase_04 AC 121 ms
55,784 KB
testcase_05 AC 120 ms
55,832 KB
testcase_06 AC 122 ms
55,636 KB
testcase_07 AC 122 ms
55,504 KB
testcase_08 AC 122 ms
55,732 KB
testcase_09 AC 122 ms
56,104 KB
testcase_10 AC 121 ms
55,776 KB
testcase_11 AC 120 ms
55,828 KB
testcase_12 AC 119 ms
56,144 KB
testcase_13 AC 121 ms
55,724 KB
testcase_14 AC 120 ms
55,764 KB
testcase_15 AC 122 ms
56,188 KB
testcase_16 AC 120 ms
55,524 KB
testcase_17 AC 120 ms
55,536 KB
testcase_18 AC 121 ms
55,536 KB
testcase_19 AC 122 ms
55,860 KB
testcase_20 AC 119 ms
56,144 KB
testcase_21 AC 120 ms
56,120 KB
testcase_22 AC 118 ms
56,016 KB
testcase_23 AC 120 ms
55,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise80{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    String one = sc.next();
    String two = sc.next();

    if(one.length() == two.length()){
      String[] arrayOne = one.split("");
      String[] arrayTwo = two.split("");

      compare(one, arrayOne, two, arrayTwo);
    }else{
      String longer = "";
      String shorter = "";
      if (one.length() > two.length()){
        longer = one;
        shorter = two;
      }else{
        shorter = one;
        longer = two;
      }

      String[] arrayOne = longer.split("");
      String[] arrayTwo = new String[longer.length()];
      String[] x = shorter.split("");
      int y = arrayTwo.length - x.length;
      for(int i = 0; i < arrayTwo.length; i++){
        if(i < y){
          arrayTwo[i] = "0";
        }else{
          arrayTwo[i] = x[i - y];
        }
      }
      compare(longer, arrayOne, shorter, arrayTwo);
    }
  }

  private static void compare(String one, String[] arrayOne, String two, String[] arrayTwo){
    for(int i = 0; i < arrayOne.length; i++){
      if(arrayOne[i].equals("4") && arrayTwo[i].equals("7")){
        arrayOne[i] = "7";
        arrayTwo[i] = "4";
      }else if(arrayOne[i].equals("7") && arrayTwo[i].equals("4")){
        arrayOne[i] = "4";
        arrayTwo[i] = "7";
      }
    }

    String newOne = String.join("", arrayOne);
    String newTwo = String.join("", arrayTwo);

    if(Integer.parseInt(newOne) > Integer.parseInt(newTwo)){
      System.out.println(one);
    }else{
      System.out.println(two);
    }
  }
}
0