問題:http://codeforces.com/contest/53/problem/A
本番(out of competition).
入力された文字列のなかで指定された文字列を先頭に含むもののうち辞書順で一番早いものを求める.なければ指定された文字列自体を出力.
ソートして比較.
コード
package s49; import java.util.*; public class A_Autocomplete { public static void main(String[] args) { Scanner s = new Scanner(System.in); String x = s.next(); int n = s.nextInt(); String[] strs = new String[n]; for (int i = 0; i < n; ++i) { strs[i] = s.next(); } Arrays.sort(strs); for (String str : strs) { if (str.startsWith(x)) { System.out.println(str); return; } } System.out.println(x); } }