Finding maximum

/* Finding max number in an integer array
using recursive method.
*/

Josephus Problem

/*
Josephus Problem
N people have decided to elect a leader by arranging themselves in a
circle and eliminating every M th person around the circle, closing
ranks as each person drops out. The problem is to find out which person
will be the last one remaining ( a mathematically inclined potential
leader will figure out ahead of time which position in the circle to take).
From Algorithms in C++.
*/

Connectivity Problem

/*
This program reads a sequence of pairs of nonnegative integers less than N from standard input (interpreting the pair p q to mean "connect object p to object q") and prints out pairs
representing objects that are not yet connected. It maintains an array id that has an entry for each object, with the property that id[p] and id[q] are equal if and only if p and q are connected. For simplicity, we define N as a compile-time constant. Alternatively, we could take it from the input and allocate the id array
dynamically.From Algorithms in C++
*/

Output of char * Variable

(from http)
A character string is of type char *. Suppose we want to print the value of that pointer,i.e., the memory address of the first
character of that string. But the << operator has been overloaded to print data of type char* as a null-terminated string.
The solution is to cast the pointer to void * (this should be done to any pointer variable the programmer wishes to output as an address.)

Restore Grub Menu


Reinstalling from LiveCD


https://help.ubuntu.com/community/RecoveringUbuntuAfterInstallingWindowsIf you cannot boot from GRUB 2 review the section Boot Problems and Rescue Mode. If a reinstall becomes necessary follow these instructions. Two methods are presented; both require booting from a LiveCD (Ubuntu 9.10, Karmic Koala or later version). If the first method does not work, follow the second method, which is more complex and contains more options and instructions.

SIMPLEST - Copy GRUB 2 Files from the LiveCD

How to load ImageIcon in aJava applet

// To load an ImageIcon in an applet, use this code:
ImageIcon img1 = new ImageIcon(getClass().getResource("a.jpg"));

// The following code doesn't work in an applet
ImageIcon img2 = new ImageIcon("a.jpg");

References of Computer Programming

  1. Algorithms in C++(3rd edition) by Robert Segewick.
  2. C++ Primer (4th edition) by Stanley B.Lippman, Josae Lajoie, Barbra, E. Moo.
  3. C++ How to Program (5th edition) by P.J. Deitel.
  4. Computer Networks (3rd edition) by Andrew S. Tanenbaum.
  5. Computer Systems A Programmer's Perspective By Randal E. Bryant

Spiral Numbers

Print spiral number array like this:

7 8 9 10
6 1 2 11
5 4 3 12

Given coordinates of a point, find the corresponding number residing on it.

There are many solutions to this problem. For example, find the number by looking for the relation(function) between the number and its coordinates. The code below solves the problem without using such kind of relation. Of course, the cost is the increase of running time.

java 乱码的解决方法

打开java控制台,在 java applet就是小程序设置部分java运行时的参数部分,加入如下参数:

-Dfile.encoding=gbk

食物属性(热温凉寒)全览

http://hi.baidu.com/ilikebbs/blog/item/f6c4dbb41105d3748ad4b2cb.html
在治疗妇科病痛经一文中曾说过:女性朋友应少吃反季食物,尽量避免寒性特别是大寒的食物。读过马悦凌老师的《不生病的智慧》一书的朋友可能会记忆深刻,书中特别指出了两个大寒的食物:西瓜和螃蟹。

西瓜之所以为大寒不足为奇,因为这是个典型的夏季才有的水果,西瓜正是为人消渴避暑而生的。可是现在的科技发达了,寒冷冬天也随处可见水果摊摆着一个又一个的大西瓜,冬天本来就是寒冷的季节,如果这种天气再吃上一个西瓜,可谓是外寒加内寒,不仅能导致人易染风寒,而且能够使病状加重,所以冬天严格来说一定要杜绝吃西瓜。