描述 给定n个字符串,请对n个字符串按照字典序排列。 输入描述:
输入第一行为一个正整数n(1≤n≤1000),下面n行为n个字符串(字符串长度≤100),字符串中只含有大小写字母。 输出描述:
数据输出n行,输出结果为按照字典序排列的字符串。
示例1
输入:
9
cap
to
cat
card
two
too
up
boat
boot
输出:
boat
boot
cap
card
cat
to
too
two
up
Solution
#include<iostream>
using namespace std;
bool CheckOrder(string str[],int n){
for(int i = 0;i<n-1;i++){
if(str[i] == str[i+1])
continue;
if(str[i+1] == str[i].substr(0,str[i+1].size())){
return false;
}
if(str[i].at(0)>str[i+1].at(0)){
return false;
}el
华为机试题目:字典序排列算法解析

本文介绍了一道华为在线测试中的编程题,要求对1000个字符串按字典序进行排列。输入包含一个正整数n及n个字符串,字符串长度不超过100,仅包含大小写字母。示例给出了9个字符串的排序结果,如'boat', 'boot', 'cap'等。解决方案可能涉及排序算法的实现。"
113045945,5000057,Apache Flink 维表关联实战:Streaming SQL Join与DataStream Join解析,"['Apache', 'Flink', 'Java', '大数据处理', '流处理']
最低0.47元/天 解锁文章
168

被折叠的 条评论
为什么被折叠?



