7-2 单词排序 (10分)
请编写程序,输入一系列单词,然后按字典顺序排序,最后输出结果。
输入格式
第一行为单词的数量 n (0<n<10000),后面有 n 行,每行一个英文单词(均由小写字母组成,且长度均不超过15个英文字母)
输出格式
共 n 行,每行一个英文单词(按字典顺序排列)
输入样例
3
stick
stock
stack
输出样例
stack
stick
stock
题意:很明确
题解:这个题卡输入输出,其实到1e5的数据java读入就很慢啦~~注意!此题就是简单快排~~~直接看代码吧!
上代码:
import java.io.*;
import java.util.*;
public class Main {
static class FastScanner{//用于快速读入大量数据
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(in),16384);
eat("");
}
public void eat(String s) {
st = new StringTokenizer(s);
}
public String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
return null;
}
}
public boolean hasNext() {
while(!st.hasMoreTokens()) {
String s = nextLine();
if(s==null) return false;
eat(s);
}
return true;
}
public String next() {
hasNext();
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static FastScanner cin = new FastScanner(System.in);//快读
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));//快速输出
public static void main(String[] args) {
String s [] = new String[1005];
int n = cin.nextInt();
for (int i = 0; i < n;i++) {
s[i]=cin.nextLine();
}
Arrays.sort(s, 0, n);
for (int i = 0; i < n;i++) {
out.println(s[i]);
}
out.flush();
}
}
来源:CSDN
作者:lgz0921
链接:https://blog.csdn.net/lgz0921/article/details/103988182