hw笔试题-02
#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的更多相关文章
- hw笔试题-01
#include <stdlib.h> #include <stdio.h> #include <string.h> int str_split(char *inp ...
- iOS笔试题02
1. Difference between shallow copy and deep copy? 1> 浅拷贝:指针(地址)拷贝,不会产生新对象 2> 深拷贝:内容拷贝,会产生新对象 2 ...
- 100 道 Linux 笔试题,能拿 80 分就算大神!
本套笔试题共100题,每题1分,共100分.(参考答案在文章末尾) 1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统C. 跟踪管理系统信息和错 ...
- 推荐收藏:100道Linux笔试题,能拿90分以上的都去了BAT
本套笔试题共100题,每题1分,共100分.(参考答案在文章末尾) 1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统 C. 跟踪管理系统信息和 ...
- 【笔试必备】常见sql笔试题(30题)
sql是测试从业者必备的技能之一,基本上也是笔试必考内容. 所以,不要让sql拖了后腿,有些测友一遇到多表关联查询就犯晕,甚至连单表的执行顺序都没搞懂,下面简单介绍下,顺便给一些题供大家练习. 单表执 ...
- 对Thoughtworks的有趣笔试题实践
记得2014年在网上看到Thoughtworks的一道笔试题,当时觉得挺有意思,但是没动手去写.这几天又在网上看到了,于是我抽了一点时间写了下,我把程序运行的结果跟网上的答案对了一下,应该是对的,但是 ...
- 从阿里巴巴笔试题看Java加载顺序
一.阿里巴巴笔试题: public class T implements Cloneable { public static int k = 0; public static T t1 = new T ...
- 我设计的ASP.NET笔试题,你会多少呢
本笔试题考查范围包括面向对象基础.HTML.CSS.JS.EF.jQuery.SQL.编码思想.算法等范围. 第1题:接口和抽象类有何区别? 第2题:静态方法和实例方法有何区别? 第3题:什么是多态? ...
- C#经典笔试题-获取字符串中相同的字符以及其个数
public Dictionary<char,int> GetStrSameAs(string str){ //将字符串转换成一个字符数组. char[] charArray=str.To ...
随机推荐
- 自己收集的好玩的JS特效(持续更新)
放到我自己的服务器上了. 网 scale.html 樱花 sakura.html
- Codeforces Round #594 (Div. 1) D2. The World Is Just a Programming Task (Hard Version) 括号序列 思维
D2. The World Is Just a Programming Task (Hard Version) This is a harder version of the problem. In ...
- Codeforces Round #598 (Div. 3) C. Platforms Jumping 贪心或dp
C. Platforms Jumping There is a river of width n. The left bank of the river is cell 0 and the right ...
- python request获取ip、获取登录设备
from flask import request 获取ip request.remote_addr 获取登录设备 request.user_agent.string
- Linux常用命令之文件编辑命令vim
vi命令 vi命令是UNIX操作系统和类UNIX操作系统中最通用的全屏幕纯文本编辑器.Linux中的vi编辑器叫vim,它是vi的增强版(vi Improved),与vi编辑器完全兼容,而且实现了很多 ...
- CAT 监控搭建
简介 CAT 是基于 Java 开发的实时应用监控平台,为美团点评提供了全面的实时监控告警服务. 已经在美团点评的基础架构中间件框架(MVC框架,RPC框架,数据库框架,缓存框架等,消息队列,配置系统 ...
- 【linux】dmesg命令显示开机信息和设备加载情况
Linux命令dmesg用来显示开机信息,kernel会将开机信息存储在ring buffer中.您若是开机时来不及查看信息,可利用dmesg来查看.开机信息亦保存在/var/log目录中,名称为dm ...
- LOAD_DLL_DEBUG_EVENT 时读取 DllName
这句话是说 lpImageName 和 hFile 存在关联(associated),不是一定指向! 继续读后面那句,“这个数字可能为NULL,或者包含着被调试进程空间中的一个字符串地址.这个地址,相 ...
- 2018-12-25-win10-uwp-通知列表
原文:2018-12-25-win10-uwp-通知列表 title author date CreateTime categories win10 uwp 通知列表 lindexi 2018-12- ...
- SPA项目开发之CRUD+表单验证
表单验证 Form组件提供了表单验证的功能,只需要通过 rules 属性传入约定的验证规则, 并将Form-Item的prop属性设置为需校验的字段名即可 <el-form-item label ...