private String count(String str) {
    	char tmp[] = str.toCharArray();
    	StringBuilder ret = new StringBuilder();
    	if (str.length() == 0) return null;
    	else if (str.length() == 1) return "1" + str;
    	else
    	{
    		for (int i = 1; i < str.length(); )
    		{
    			int j = i;
    			int num = 1;
    			while (j < str.length() && tmp[j] == tmp[j-1])
    			{
    				num++;
    				j++;
    			}
    			ret.append(Integer.toString(num)).append(tmp[j-1]);
    			i = j+1;
    		}
    		if (tmp[str.length()-1] != tmp[str.length()-2])
    		{
    			ret.append("1").append(tmp[str.length()-1]);
    		}
    	}
        return ret.toString();
    }