Daily Archives: September 21, 2012

Beautiful enums

Beautiful enums Whatever complaints you may have against java, I think you have to grant that at least enums are a thing of beauty. Consider this code line: Collections.sort(myChildren, Child.Order.ByAge.descending()); The best part is that this started to appear as … Continue reading

Posted in Uncategorized | Leave a comment

编程之美 寻找发帖水王 扩展问题

http://blog.csdn.net/super_chris/article/details/7187376   扩展问题是这样的,如果没有超级水王了,可是有三个ID在列表中出现的次数都超过了1/4,怎么找出这三个ID? 思路是类似的,同样,每次删除4个不同的ID,不影响“那三个ID在剩余ID中出现仍然超过1/4”这一事实,因此我们可以每次删除4个不同的ID,直到剩下3个ID为止。具体编程中怎么体现“删除四个不同ID”这一动作呢?我是这样做的。用candidate[3]记录三个候选ID,用count[3]记录它们的累积次数,然后遍历整个ID列表,每处理一个ID,若与candidate[i]中的某一个相同,则count[i]++,若与三个都不同,则说明找到了四个互不相同的ID,将三个count[i]–,也就相当于“删除了四个不同ID”,若某一个count[i]==0,则更新之。 之前想这个问题的时候一直没想出来,好像也有过类似思路却一直觉得不正确,这次简单的测试了几组数据,貌似没有问题。如有错误,欢迎指正。 代码如下: #include <iostream>  using namespace std;  int candidate[3];  int count[3] = {0};  int input[100];  int num = 0;  int main()  {      cout<<“please input”<<endl;      int t;      while(cin>>t)      {          if (t == … Continue reading

Posted in Uncategorized | Leave a comment

cc 9-5

package Question9_5; import java.util.ArrayList; public class Question {    public static int search(String[] strings, String str, int first, int last) {        while (first <= last) {            // Ensure there is something at the end            while (first <= last && strings[last] == … Continue reading

Posted in Uncategorized | Leave a comment

cc 9-3

package Question9_3; public class Question {     public static int search(int a[], int l, int u, int x) {        while (l <= u) {            int m = (l + u) / 2;            if (x == a[m]) {                return m;            }            … Continue reading

Posted in Uncategorized | Leave a comment

career code c

https://github.com/parker0203/careercup

Posted in Uncategorized | Leave a comment

Interview Questions – vijaytechi

https://sites.google.com/site/vijaytechi/interview

Posted in Uncategorized | Leave a comment

编程之美 读书笔记

http://www.cnblogs.com/flyinghearts/category/260827.html

Posted in Uncategorized | Leave a comment