#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 ;
}

最新文章

  1. 3. Python 简介
  2. 使用腾讯开发平台获取QQ用户数据资料
  3. SQL server2000更改数据库名称
  4. 2016年12月24日 星期六 --出埃及记 Exodus 21:19
  5. &#39;UserInfoBLL&#39; node cannot be resolved for the specified context [MVC展示数据.Controllers.LoginController]问题解决
  6. golang rbac框架
  7. Qt之HTTPS登录
  8. js判断主流浏览器类型和版本号
  9. MAC OS中使用ll,la命令
  10. MongoDB appendix
  11. ZOJ 3329 One Person Game 【概率DP,求期望】
  12. hdu4771 Stealing Harry Potter&amp;#39;s Precious
  13. 用Visual Studio2017写静态库
  14. 芝麻HTTP: Python爬虫入门之Urllib库的高级用法
  15. Python&#160;对服务器返回数据编码进行判断之chardet
  16. 朱晔的互联网架构实践心得S2E4:小议微服务的各种玩法(古典、SOA、传统、K8S、ServiceMesh)
  17. 转:eclipse maven build、maven install 等区别
  18. 面试题-JAVA算法题
  19. css基础 -文本溢出 text-overflow:ellipsis;
  20. Atcoder Yet Another Palindrome Partitioning(状压dp)

热门文章

  1. DirectShow 应用开发过程
  2. 大话设计模式Python实现-组合模式
  3. 安装keepalived OpenSSL is not properly installed on your system. !!!
  4. python基础(13):函数名的使用、第一类对象、闭包、迭代器
  5. python基础(1):python介绍、python发展史
  6. Python制作动态二维码只需要一行代码!炒鸡简单!
  7. 【LeetCode】58.最后一个单词的长度
  8. redis删除策略
  9. MySQL 主从复制(实时热备)原理与配置
  10. CentOS7破解root密码