結果
| 問題 | No.293 4>7の世界 | 
| コンテスト | |
| ユーザー |  kenji_shioya | 
| 提出日時 | 2016-06-14 06:14:33 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 155 ms / 2,000 ms | 
| コード長 | 1,608 bytes | 
| コンパイル時間 | 5,005 ms | 
| コンパイル使用メモリ | 77,952 KB | 
| 実行使用メモリ | 41,524 KB | 
| 最終ジャッジ日時 | 2024-12-30 12:07:38 | 
| 合計ジャッジ時間 | 10,176 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 20 | 
ソースコード
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);
    }
  }
}
            
            
            
        