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 ...
随机推荐
- 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 ...
- IT兄弟连 Java语法教程 赋值运算符
从本书之前的内容中就一直在使用赋值运算符.现在是正式介绍赋值运算符的时候了.赋值运算符是单个等号”=“.在Java中,赋值运算符的工作方式与所有其它计算机语言相同.它的一般形式如下: var = ex ...
- day01(无用)
第一讲:1,基本理论知识 第一天内容:抽象.枯燥. 2,工具的操作: 三个工具: 2个发包工具: Jmeter.PostMan 1个抓包工具: Fiddler 3,安全测试的内容: 初级,工具的使用: ...
- 一个有用的排序函数,array_multisort(),下面的一个用法是根据二维数组里的一个字段值的大小,对该二维数组进行重新排序
从二维数组$cashes中取出一列 'store_id'(二维数组中的每个一维数组都有的字段),按照这个的大小排序,对二维数组$caches里面的一维数组进行重新排序 实际应用如下 想让相同部门的排在 ...
- 删除链表的中间节点和a/b处的节点
问题描述: 删除链表的中间节点和a/b处的节点 给定链表的头结点head,实现删除链表的中间节点的函数: 例如: 不删除任何节点: 1-->2,删除节点1: 1-->2-->3,删除 ...
- asp.net 使用NPOI读取excel文件
asp.net 使用NPOI读取excel文件内容 NPOI下载地址:NPOI public class ExcelHelper { /// <summary> /// 读取Excel文件 ...
- sql server 查询出整数 (可灵活运用)
系统辅助用表,常用来获取数字,当然还有其他用途
- Spring Boot 中如何定制 Banner
本人免费整理了Java高级资料,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G,需要自己领取.传送门:h ...
- Docker配置yapi接口
一.安装Docker 第一步:yum 包更新到最新 sudo yum update 第二步:安装需要的软件包 yum-util 提供yum-config-manager功能,另外两个是devicema ...
- MySqlBulkLoader 中文乱码
MySQL驱动:MySqlConnector GitHub地址:https://github.com/mysql-net/MySqlConnector.git 文档地址:https://mysql-n ...