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 ...
随机推荐
- 新书上线:《Spring Boot+Spring Cloud+Vue+Element项目实战:手把手教你开发权限管理系统》,欢迎大家买回去垫椅子垫桌脚
新书上线 大家好,笔者的新书<Spring Boot+Spring Cloud+Vue+Element项目实战:手把手教你开发权限管理系统>已上线,此书内容充实.材质优良,乃家中必备垫桌脚 ...
- Codeforces Round #603 (Div. 2) B. PIN Codes 水题
B. PIN Codes A PIN code is a string that consists of exactly 4 digits. Examples of possible PIN code ...
- Codeforces Round 596 题解
万幸的是终于碰上了一场上分好场. 不幸的是一开始差点不会 A. 万幸的是想了个不那么稳的结论过了 pretest. 不幸的是罚时很高,而且慌得一比. 万幸的是然后半个小时内把 B 和 C 码了. 不幸 ...
- java(二)变量
基础数据类型: 数值型:整型(byte.short.int.long).浮点型(float.double)java各整数类型有固定的表数范围和字段长度,不受具体os的影响,以保持java的可移植性:j ...
- spring cloud 2.x版本 Spring Cloud Stream消息驱动组件基础教程(kafaka篇)
本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka-ri ...
- 前端笔记之React(一)初识React&组件&JSX语法
一.React项目起步配置 官网:https://reactjs.org/ 文档:https://reactjs.org/docs/hello-world.html 中文:http://react.c ...
- oracle 中 to_date 函数的用法
常犯错的使用方法. to_date('2019-08-12 22:05:','yyyy-MM-dd HH24:mm:ss') Oracle中会引起错误:"ORA 01810 格式代码出现两次 ...
- 关于EFCore线程内唯一
EntityFramework的线程内唯一 EntityFramework的线程内唯一是通过httpcontext来实现的 public static DbContext DbContext() { ...
- MongoDB 高级教程
MongoDB 关系 MongoDB 的关系表示多个文档之间在逻辑上的相互联系. 文档间可以通过嵌入和引用来建立联系. MongoDB 中的关系可以是: 1:1 (1对1) 1: N (1对多) N: ...
- 资深程序员:学Python我推荐你用这几款编辑器
Python使用什么编辑比较好,Python编辑器推荐 各位 Pythoner 好啊!在这个烦躁的时代,相聚就是缘分,很高兴各位 Pythoner 能相聚于此,希望接下来的路,我们一起走下去,使用 P ...