奇虎360 2015校园招聘笔试编程题
2017-08-23 20:47
239 查看
题目一:
题目二:
分析:
1、浮点数比较大小。
2、必须以右上角或者左下角为起点。
题目三:
这道题不清楚题意是求最长公共子序列还是将字符串分隔为单词,然后求两个字符串中共有的字符串里面最长的。
我将两种情况下的思路和代码都写下来。
1、求字符串A和B的最长公共子序列。
这是个经典题目,要使用到动态规划。
关于动态规划,参考这里:动态规划
2、将字符串分隔为单词,然后求两个字符串中共有的字符串里面最长的。
这种解决方法,我能想到的思路就是将每个句子中的单词分析出来保存到一个数组中,然后将这两个数组中的单词进行比较,这样的时间复杂度能达到O(m*n),时间效率非常低,还没有遇到什么有效地解法,由于解法很直观就不用关注代码了。
写一个函数,根据两文件的绝对路径算出相对路径。 如a="/qihoo/app/a/b/c/d/new.c",b="/qihoo/app/1/2/test.c", 那么b相对于a的相对路径是"../../../../1/2/test.c"
#include <stdio.h> #include <string.h> int isGoodPath( char *path ) { if ( path == NULL || *path != '/' ) return 0; return 1; } //the relative path of b void parseRelativePath( char *patha, char *pathb, char *result ) { if ( !isGoodPath( patha ) || !isGoodPath( pathb ) ) return ; int diff, i = 0; int tempdiff; int dirDiff = 0; //找到路径中最后一个相同的目录 while ( *(patha+i) == *(pathb+i) ) { if ( *(patha+i) == '/' ) { diff = i; } i++; } diff++; tempdiff = diff; //计算出..的个数 while ( *(patha+diff) != '\0' ) { if ( *(patha+diff) == '/' ) dirDiff++; diff++; } //拼接出结果 while ( dirDiff != 0 ) { strcat( result, "../" ); dirDiff--; } strcat( result, pathb+tempdiff ); } int main( void ) { char *patha = "/qihoo/app/a/b/c/d/new.c"; char *pathb = "/1/2/test.c"; char result[1024]; parseRelativePath( patha, pathb, result ); printf( "%s\n", result ); return 0; }
题目二:
有一个二维float型矩阵,有m行n列,每一个行和列上都是递减序列, 请编程实现在这个矩阵中查找值等于v的元素的函数,如果找到返回其下标
分析:
1、浮点数比较大小。
2、必须以右上角或者左下角为起点。
#include <stdio.h> #include <math.h> #include <unistd.h> //row -> m, column -> n int findFromMatrix( float target, float *matrix, int m, int n ) { const float REALZERO = 10.0e-6; const float PREALZERO = -1 * 10.0e-6; for ( int i = 0, j = n-1; j >= 0 && i < m; ) { printf( "i : %d\n", i ); printf( "j : %d\n", j ); sleep(1); if ( fabs(matrix[i*m+j] - target) < REALZERO ) { return i*m+j; } else if ( matrix[i*m+j] - target < PREALZERO ) { i++; } else { j--; } } return -1; } int main( void ) { float matrix[] = { 1.0, 2.0, 8.0, 9.0, 2.0, 4.0, 9.0, 12.0, 4.0, 7.0, 10.0, 13.0, 6.0, 8.0, 11.0, 15.0 }; float target = 4.0; int index = findFromMatrix( target, matrix, 4, 4 ); printf( "%d\n", index ); return 0; }
题目三:
字符串A和B的最长公共单词
这道题不清楚题意是求最长公共子序列还是将字符串分隔为单词,然后求两个字符串中共有的字符串里面最长的。
我将两种情况下的思路和代码都写下来。
1、求字符串A和B的最长公共子序列。
这是个经典题目,要使用到动态规划。
关于动态规划,参考这里:动态规划
2、将字符串分隔为单词,然后求两个字符串中共有的字符串里面最长的。
这种解决方法,我能想到的思路就是将每个句子中的单词分析出来保存到一个数组中,然后将这两个数组中的单词进行比较,这样的时间复杂度能达到O(m*n),时间效率非常低,还没有遇到什么有效地解法,由于解法很直观就不用关注代码了。
相关文章推荐
- 奇虎360 2015校园招聘笔试编程题
- 奇虎360 2015校园招聘笔试编程题
- 奇虎360 2015校园招聘笔试编程题
- 奇虎360校园招聘2015笔试题目
- 奇虎360_2017校园招聘笔试编程题第一题
- 2012年奇虎360校园招聘实习生笔试编程题
- 奇虎360_2017校园招聘笔试编程题第二题
- 微软2014校园招聘笔试编程题
- 2015华为校园招聘机试题+1道2013年网易校园招聘笔试题
- 阿里巴巴2015秋季校园招聘前端开发工程师在线笔试题及答案
- 百度2015校园招聘软件开发笔试题
- 腾讯2015校园招聘技术类研发笔试题第七题
- 2015网易游戏校园招聘笔试题 游戏插件研发岗
- 2015校园招聘雅虎北京研发笔试题 系统运维岗
- 中科创达2015校园招聘Java卷的笔试题及附加题答案
- 多益网络2015校园招聘第二次笔试题
- 阿里巴巴2015秋季校园招聘前端开发工程师在线笔试题及答案
- 同花顺2015校园招聘笔试题
- 百度2015校园招聘笔试题——研发工程师(西安站)
- 2015大众点评校园招聘笔试题——比较两个字符串的相同部分和不同部分