题目:已知字母序列【d, g, e, c, f, b, o, a】,请实现一个函数针对输入的一组字符串 input[] = {"bed", "dog", "dear", "eye"},按照字母顺序排序并打印,结果应为:dear, dog, eye, bed。
考察知识点:字符串的大小比较
代码如下:
#include "stdafx.h"
#include <map>
#include <assert.h>
#include <vector>
#include <algorithm>
#include <iostream>
std::map<char, int> char_int_map;
//比较两个字符串的大小(此函数纯属练手)
//str_a大于str_b,则返回1;相等则返回0;小于则返回-1
int compare_string(char *str_a, char *str_b)
{
assert(str_a != NULL && str_b != NULL);
int result = 0;
char *pa = str_a;
char *pb = str_b;
while (*pa != '\0' &a

博客内容介绍了如何使用给定字母顺序对一组字符串进行排序。题目要求根据字母序列【d, g, e, c, f, b, o, a】,对输入的字符串如{"bed", "dog", "dear", "eye"}按特定顺序输出。解决方案主要涉及字符串比较的算法实现。"
124154856,13451890,Java开发全攻略:从基础到高级,"['Java开发', 'Web开发', '数据库开发', '框架与工具', '分布式架构']
最低0.47元/天 解锁文章
2万+

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



