#include<stdio.h>
#include<string.h> typedef struct
{
char *mem;
char len;
}m_table_t; int table_cmp(m_table_t *p1, m_table_t *p2)
{
int ret;
if(p1->len == p2->len)
return memcmp(p1->mem, p2->mem, p1->len);
if(p1->len > p2->len)
ret = memcmp(p1->mem, p2->mem, p2->len);
else
ret = memcmp(p1->mem, p2->mem, p1->len);
if( == ret)
return p1->len - p2->len; return ret;
} void sort(m_table_t *a, int num)
{
int i,j;
m_table_t temp;
for(i=;i<num;i++)
{
for(j=;j<num;j++)
{
if( table_cmp(&a[j], &a[j+] ) > )
{
memcpy( &temp, &a[j], sizeof(m_table_t) );
memcpy( &a[j], &a[j+], sizeof(m_table_t) );
memcpy( &a[j+], &temp, sizeof(m_table_t) );
}
}
}
} void quickSort(m_table_t *s, int l, int r)
{
int i, j;
m_table_t x;
if (l < r)
{
i = l; j = r;
memcpy(&x, &s[i], sizeof(m_table_t) );
while (i < j)
{
while(i < j && (table_cmp(&s[j], &x) > )) j--;
if(i < j)
{
memcpy( &s[i++], &s[j], sizeof(m_table_t) );
}
while(i < j && (table_cmp(&x, &s[i]) > )) i++;
if(i < j)
{
memcpy(&s[j--], &s[i], sizeof(m_table_t) );
}
}
memcpy(&s[i], &x, sizeof(m_table_t) );
quickSort(s, l, i - );
quickSort(s, i + , r);
}
} int str2table(m_table_t *table, char *str, int *index)
{
int i,w;
*index = ;
for(i=,w= -; i<strlen(str); i++)
{
if(' ' != *(str+i) )
{
if( (- == w) )
{
w = i;//start
}
}
else
{
if(- != w)//stop
{
table[*index].mem = str+w;
table[*index].len = i - w;
(*index)++;
w = -;
}
}
}
if(- != w)
{
table[*index].mem = str+w;
table[*index].len = i - w;
(*index)++;
w = -;
}
return ;
} void display(m_table_t *table, int index)
{
int i;
char tmp[] = {};
for(i=; i<index; i++)
{
memset(tmp, , );
memcpy(tmp, table[i].mem, table[i].len);
printf("%s\n", tmp);
}
return;
} int main(void )
{
int index;
char input[] = {};
m_table_t g_table[]= {}; gets(input); str2table(&g_table[], input, &index); quickSort(&g_table[], , index-);//sort(&g_table[0], index-1); display(&g_table[], index);
return ;
}

hw笔试题-02的更多相关文章

  1. hw笔试题-01

    #include <stdlib.h> #include <stdio.h> #include <string.h> int str_split(char *inp ...

  2. iOS笔试题02

    1. Difference between shallow copy and deep copy? 1> 浅拷贝:指针(地址)拷贝,不会产生新对象 2> 深拷贝:内容拷贝,会产生新对象 2 ...

  3. 100 道 Linux 笔试题,能拿 80 分就算大神!

    本套笔试题共100题,每题1分,共100分.(参考答案在文章末尾) 1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统C. 跟踪管理系统信息和错 ...

  4. 推荐收藏:100道Linux笔试题,能拿90分以上的都去了BAT

    本套笔试题共100题,每题1分,共100分.(参考答案在文章末尾) 1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统 C. 跟踪管理系统信息和 ...

  5. 【笔试必备】常见sql笔试题(30题)

    sql是测试从业者必备的技能之一,基本上也是笔试必考内容. 所以,不要让sql拖了后腿,有些测友一遇到多表关联查询就犯晕,甚至连单表的执行顺序都没搞懂,下面简单介绍下,顺便给一些题供大家练习. 单表执 ...

  6. 对Thoughtworks的有趣笔试题实践

    记得2014年在网上看到Thoughtworks的一道笔试题,当时觉得挺有意思,但是没动手去写.这几天又在网上看到了,于是我抽了一点时间写了下,我把程序运行的结果跟网上的答案对了一下,应该是对的,但是 ...

  7. 从阿里巴巴笔试题看Java加载顺序

    一.阿里巴巴笔试题: public class T implements Cloneable { public static int k = 0; public static T t1 = new T ...

  8. 我设计的ASP.NET笔试题,你会多少呢

    本笔试题考查范围包括面向对象基础.HTML.CSS.JS.EF.jQuery.SQL.编码思想.算法等范围. 第1题:接口和抽象类有何区别? 第2题:静态方法和实例方法有何区别? 第3题:什么是多态? ...

  9. C#经典笔试题-获取字符串中相同的字符以及其个数

    public Dictionary<char,int> GetStrSameAs(string str){ //将字符串转换成一个字符数组. char[] charArray=str.To ...

随机推荐

  1. 通过windows组策略配置时间同步

    Windows系统中带有NTP服务器和客户端的程序,只需在Windows中简单配置即可实现电脑之间的时间同步. 网上常见的配置NTP服务器的方法是修改系统注册表,这种方法是微软不推荐的.在实际使用中, ...

  2. super()方法详解

    目录 一.单独调用父类的方法 二.super() 方法基本概念 2.1 描述 2.2 语法 2.3 单继承使用super() 2.4 多继承使用super() 三.注意事项 四.练习 一.单独调用父类 ...

  3. 【Resharper】C# “Simplify conditional ternary expression”

    #事故现场: 对某个对象做空值检测的时候,结合三元运算符给某变量赋值的时候,R#提示:"Simplify conditional ternary expression" : R#建 ...

  4. python做中学(八)匿名函数lambda的用法

    匿名函数,顾名思义即没有名称的函数,和def定义的函数的最大区别在于匿名函数创建后返回函数本身(即匿名函数不需要return来返回值),表达式本身结果就是返回值,而def创建后则赋值给一个变量名,在P ...

  5. URLDecoder异常Illegal hex characters in escape (%)

    URLDecoder对参数进行解码时候,代码如: URLDecoder.decode(param,"utf-8"); 有时候会出现类似如下的错误: URLDecoder异常Ille ...

  6. 使用paramiko模块进行封装,远程操作linux主机

    import time import paramiko class HandleParamiko: ''' 定义一个linux处理类 ''' def __init__(self, hostname, ...

  7. 洛谷 P4999(数位DP)

    ###洛谷 P4999 题目链接 ### 题目大意:给你一个区间,求这段区间中所有数的,数位上的,数字之和. 分析: 这题与 洛谷 P2602 相似,稍微改一下就可以了. 求出 0 ~ 9 的个数,然 ...

  8. Bag of Tricks for Image Classification with Convolutional Neural Networks

    这篇文章来自李沐大神团队,使用各种CNN tricks,将原始的resnet在imagenet上提升了四个点.记录一下,可以用到自己的网络上.如果图片显示不了,点击链接观看 baseline mode ...

  9. SecureCRT连接本地虚拟机Linux系统很慢

    SSH配置问题 cd /etc/ssh/ 备份一下配置文件 cp sshd_config sshd_config.2019-07-17.bak 修改配置 vim sshd_config 重启sshd服 ...

  10. Elastic:如何在一个机器上同时模拟多个node

    Elastic:如何在一个机器上同时模拟多个node /bin/elasticsearch -E node.name=node1 -E cluster.name=my-application -E p ...