华为笔试题
2016-04-02 16:33
155 查看
题目描述
给定n个字符串,请对n个字符串按照字典序排列。
输入描述:
输入第一行为一个正整数n(1≤n≤1000),下面n行为n个字符串(字符串长度≤100),字符串中只含有大小写字母。
输出描述:
数据输出n行,输出结果为按照字典序排列的字符串。
输入例子:
9
cap
to
cat
card
two
too
up
boat
boot
输出例子:
boat
boot
cap
card
cat
to
too
two
up
给定n个字符串,请对n个字符串按照字典序排列。
输入描述:
输入第一行为一个正整数n(1≤n≤1000),下面n行为n个字符串(字符串长度≤100),字符串中只含有大小写字母。
输出描述:
数据输出n行,输出结果为按照字典序排列的字符串。
输入例子:
9
cap
to
cat
card
two
too
up
boat
boot
输出例子:
boat
boot
cap
card
cat
to
too
two
up
import java.util.*; public class Huawei{ public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); Vector<String> ve=new Vector<String>(); for (int i = 0; i < n; i++) { ve.add(in.next()); } Collections.sort(ve); Iterator<String> it=ve.iterator(); while(it.hasNext()){ System.out.println(it.next()); } } }
相关文章推荐
- Catch That Cow(bfs)
- VS2010+OpenCV的SDI应用——(一)打开图像
- 剑指 offer代码解析——面试题39判断平衡二叉树(高效方法)
- [Python笔记][第四章Python正则表达式]
- 图的最短路径
- [Python笔记][第四章Python正则表达式]
- 剑指 offer代码解析——面试题39判断平衡二叉树(高效方法)
- struts2入门
- android每次版本更新显示欢迎页
- android开发 Fragment嵌套调用常见错误
- bzoj3295 动态逆序对
- Android 案例 登录界面
- [Python笔记][第三章Python选择与循环]
- [Python笔记][第三章Python选择与循环]
- Android 电源管理 -- wakelock机制
- MFC-线程同步
- pycharm5.0专业版出现的乱码问题
- c# 技巧之 泛型方法
- C++中的vector
- JS 间隔固定时间重复运行的方法