結果

問題 No.293 4>7の世界
ユーザー ottfoekst
提出日時 2015-11-08 02:18:38
言語 Java
(openjdk 23)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 4,972 ms
コンパイル使用メモリ 75,484 KB
実行使用メモリ 41,428 KB
最終ジャッジ日時 2024-12-30 11:33:52
合計ジャッジ時間 9,392 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No293 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String[] numList = scanner.nextLine().split(" ");
		System.out.println(compare(numList[0], numList[1]) > 0 ? numList[0] : numList[1]);
		scanner.close();
	}
		
	private static int compare(String str1, String str2) {
		if(str1.length() > str2.length()) {
			return 1;
		}
		else if(str1.length() < str2.length()) {
			return -1;
		}
		else {
			for(int index = 0; index < str1.length(); index++) {
				char str1Char = str1.charAt(index);
				char str2Char = str2.charAt(index);
				if(str1Char == '4' && str2Char == '7' ) {
					return 1;
				}
				else if(str1Char == '7' && str2Char == '4') {
					return -1;
				}
				else {
					if(str1Char != str2Char) {
						return str1Char - str2Char;
					}
				}
			}
			return 0;
		}
	}
}
0