2014去哪儿网几道题

来源:互联网 发布:淘宝二合一口令api 编辑:程序博客网 时间:2024/04/28 05:41

2014去哪儿网校园招聘(沈阳)

分类: 面试题 Hiring Written Test 1049人阅读 评论(0) 收藏 举报

2013-09-10






a) 
SELECT sno, cno, grade
FROM scg
WHERE grade < 60;

b)
SELECT sno, COUNT(cno)
FROM scg
WHERE grade>=90
GROUP BY sno HAVING COUNT(cno)>2
ORDER BY COUNT(cno) DESC;

c)

SELECT TOP 3 sno, cno, grade

FROM scg

GROUP BY sno

ORDER BY sno, grade;

d)

[sql] view plaincopy
  1. SELECT cno, first.sno, second.sno, first.grade, second.grade, first.grade-second.grade  
  2. FROM   
  3. (   
  4. SELECT TOP 1 *   
  5. FROM scg   
  6. GROUP BY cno   
  7. ORDER BY grade  
  8. first,  
  9.       (  
  10. SELECT TOP 1 *  
  11. FROM  
  12. SELECT TOP 2 *   
  13. FROM scg  
  14. GROUP BY cno  
  15. ORDER BY grade DESC  
  16. ) two  
  17. GROUP BY two.cno  
  18. ORDER BY two.grade  
  19. second  
  20. ;  


已知字母序列【d, g, e, c, f, b, o, a】,请实现一个函数针对输入的一组字符串 input[] = {"bed", "dog", "dear", "eye"},按照字母顺序排序并打印。

本例的输出顺序为:dear, dog, eye, bed。


[java] view plaincopy
  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3.   
  4. void swapstr(char **a,char **b){  
  5.     if(a!=b){  
  6.     char *tmp=*a;  
  7.     *a=*b;  
  8.     *b=tmp;  
  9.     }  
  10. }  
  11.   
  12. int compare(char *a,char *b,char *hashstr){  
  13.     int lena=strlen(a);  
  14.     int lenb=strlen(b);  
  15.     int i=0;int j=0;  
  16.    while(i<lena&&j<lenb){  
  17.         printf("%d---%d\n",hashstr[*(a+i)],hashstr[*(b+j)]);  
  18.     if(hashstr[*(a+i)]<hashstr[*(b+j)]){  
  19.         return 1;  
  20.     }else if(hashstr[*(a+i)]>hashstr[*(b+j)]){  
  21.      return -1;  
  22.    }  
  23.    i++;j++;  
  24.    }  
  25.    if((i==lena)&&(j==lenb))  
  26.    {  
  27.      return 0;  
  28.    }  
  29.    if(i==lena){  
  30.     return -1;  
  31.    }  
  32.    if(j==lenb){  
  33.     return 1;  
  34.    }  
  35. }  
  36. int main()  
  37. {  
  38.     char seq[]="dgecfboa";  
  39.     char hashstr[256];  
  40.     int count=0;  
  41.     memset(hashstr,0,256);  
  42.     int i;  
  43.     for(i=0;seq[i]!='\0';i++){  
  44.         hashstr[seq[i]]=count++;  
  45.     }  
  46.     char arrstr[][5]={"bed","dog","dear","eye"};  
  47.     int j,k;  
  48.     int maxword;  
  49.     int retu;  
  50.     for(j=0;j<4;j++){  
  51.       maxword=j;  
  52.       for(k=j+1;k<4;k++){  
  53.            retu=compare(arrstr[k],arrstr[maxword],hashstr);  
  54.         if(retu>0){  
  55.             maxword=k;  
  56.         }  
  57.        }  
  58.         swapstr(&arrstr[j],&arrstr[maxword]);  
  59.     }  
  60.   
  61.     for(int x=0;x<4;x++){  
  62.         printf("%s\n",arrstr[x]);  
  63.     }  
  64.     return 0;  
  65. }  

0 0
原创粉丝点击