find 3 indexes
来源:互联网 发布:电子琴教学视频软件 编辑:程序博客网 时间:2024/05/06 03:27
陈利人老师的新浪微博面试题
/*===============================================================** Author: lizhao(clark)** E-mail: lzclark27@gmail.com** company: ** Last modified: 2013-03-28 10:30** Filename: findThreeSequence.c** Description: http://weibo.com/1915548291/zpuaLlfh5#_rnd1364437842264*===============================================================*/#include <stdio.h>struct myresult{int n[3];};int find3Sequence(int a[], int n, struct myresult *res){if(!a || n<3 || !res)return -1;int i, nMax=-1;for(i=0;i<sizeof(struct myresult)/sizeof(int);++i)res->n[i] = -1;res->n[2] = n-1;for(i=n-2;i>=0;--i){if(a[i] < a[res->n[2] ]){if(-1 == res->n[1]){res->n[1] = i;}else if(a[i] > a[ res->n[1] ]){//replace the second numberres->n[1] = i;}else{res->n[0] = i;return 0;}}else{if(-1 == res->n[1]){res->n[0] = i;}else if(-1==nMax){nMax = i;}else if(a[i] > a[nMax]){nMax = i;}else{res->n[2] = nMax;res->n[1] = i;}}}}int main(int argc, char **argv){int i;struct myresult res;//int array1[] = {1, 4, 2, 3};int array1[] = {6, 7, 8, 9, 3, 4, 5};if(find3Sequence(array1, sizeof(array1)/sizeof(int), &res) == 0){printf("find array1:");for(i=0;i<sizeof(res)/sizeof(int);++i)printf("a[%d]=%d\n", res.n[i], array1[ res.n[i] ]);}elseprintf("not find!\n");return 0;}
- find 3 indexes
- indexes
- indexes
- CareerCup Find 3 indexes i,j,k such that, i<j<k and a[i] < a[j] < a[k]
- Find out the missing indexes and their usefulness
- 3 Indexes and Index-Organized Tables读书笔记
- MySQL Optimization Part 3 - Indexes Operations
- 3 Indexes 若该目录下无index文件
- Database Indexes
- Partitioned Indexes
- 11 Indexes
- 《Microsoft Sql server 2008 Internals》读书笔记--第六章Indexes:Internals and Management(3)
- Finding duplicate indexes
- reorganizing regenerated indexes
- Detecting duplicate Oracle indexes
- identifing unused indexes
- 什么是“Using Covering Indexes”
- 禁止 Myeclipse updating indexes
- 路由器和交换机的区别
- 在Android源码下编译C文件
- 指针做形参做局部变量以及内存分配
- DJANGO 数据库API (转) 很有用
- 两个uchar 组合成一个uint
- find 3 indexes
- max sum
- Oracle 高水位线收缩示例
- Js setInterval与setTimeout(定时执行与循环执行)的代码(可以传入参数)
- “class”类型重定义 || 防止头文件重复加载 || 两个类之间互相引用
- 利用jdk1.6的jax-ws 学习简单的web service
- VRML---第三章第一部分(坐标变换节点)
- 两个常见位操作面试题 不用加减乘除运算符计算两数之和及a=b*3
- openWrt软件开发教程1(交叉编译和ipk包生成)