摘要: 哪里不对??有重复时注意排名顺序。 1 2 3 3 5 不是 1 2 3 3 4 。。。。。#includetypedef struct tagStudent{ char id[7]; int grades[4]; //acme int ranks[4]; //acme}Student;typedef int (*CmpFun)(const void *a,const void *b);int cmpa(const void *a ,const void *b){ Student* sa = (Student*)a; Student* sb = (Studen... 阅读全文
posted @ 2013-07-09 17:51 summer_zhou 阅读(300) 评论(0) 推荐(0)
摘要: Q:Areversible primein any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime.Now given any two positive integers N (1#includeint isPrime(int n){ int i; if(n==0||n= 阅读全文
posted @ 2013-07-09 10:26 summer_zhou 阅读(326) 评论(0) 推荐(0)
摘要: Q:Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1, 104]. The first one who bets on a unique number wins. For example, if there are 7 people betting on 5 31 5 88 67 88 17, then the s 阅读全文
posted @ 2013-07-07 15:36 summer_zhou 阅读(220) 评论(0) 推荐(0)
摘要: Q:This time, you are supposed to find A+B where A and B are two polynomials.InputEach input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1N2 aN2... NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi( 阅读全文
posted @ 2013-07-02 15:28 summer_zhou 阅读(253) 评论(0) 推荐(0)
摘要: Q:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct order,"()"and"()[]{}"are all valid but"(]"and"([)]"are not.A 阅读全文
posted @ 2013-06-27 17:12 summer_zhou 阅读(149) 评论(0) 推荐(0)
摘要: Q:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as1and0respectively in the grid.For example,There is one obstacle in the middle of a 3x3 grid as illustrated below.[ [0,0,0], [0, 阅读全文
posted @ 2013-06-23 21:49 summer_zhou 阅读(191) 评论(0) 推荐(0)
摘要: 动态规划 int uniquePaths(int m, int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(m==0||n==0) return 0; vector > pathCounts; int i,j; for(i=0;i(n)); for(j=0;j<n;j++) ... 阅读全文
posted @ 2013-06-23 19:29 summer_zhou 阅读(136) 评论(0) 推荐(0)
摘要: 动态规划 //DP int minPathSum(vector > &grid) { // Start typing your C/C++ solution below // DO NOT write int main() function if(grid.size()==0) return 0; int m = grid.size(); int n = grid[0].size(); vector > minSum; in... 阅读全文
posted @ 2013-06-23 17:24 summer_zhou 阅读(195) 评论(0) 推荐(0)
摘要: Q:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.Note:Givenm,nsatisfy the following condition:1 next; count++; } temp = tail = cur; cur = cur->next; ... 阅读全文
posted @ 2013-06-18 11:21 summer_zhou 阅读(162) 评论(0) 推荐(0)
摘要: Q:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.A: 像mergesort一样,两两merge。递归版本: ListNode *merge(ListNode *list1,ListNode *list2) { if(!list1) return list2; if(!list2) return list1; ListNode *head; ... 阅读全文
posted @ 2013-06-18 10:36 summer_zhou 阅读(212) 评论(0) 推荐(0)