package offer_aimTo;
/**
 * 
 * @author gyt
 * 
 * ¶þÎ¬Êý×éÊÇÉÏÏÂÓÐÐò£¬×óÓÒÓÐÐò£¬²éÕÒ¸ø¶¨ÖµÊÇ·ñÔÚÆäÖÐ
 * 
 * ÀýÈç£º
 *  1 2 8 9 
 *  2 4 9 12 
 *  4 7 10 13
 *  6 8 11 15
 *  
 *  Ë¼Â·£º
 *  ÒÔ7ÎªÀý
 *  Ê×ÏÈ¼ì²éÓÒÉÏ½Ç£¬9£¬´óÓÚ7£¬ÔòÕâÒ»ÁÐ¶¼²»»áÓÐ
 *  È»ºó×óÒÆ£¬8£¬´óÓÚ7£¬ÕâÁÐÒ²Ã»ÓÐ
 *  ×óÒÆ2£¬Ð¡ÓÚ7£¬ÏÂÒÆ£¬4£¬ÏÂÒÆ7
 *  
 *  ÈôÎª6 ÒÆµ½7Ö®ºó£¬×óÒÆ£¬4£¬ÔÙÏÂÒÆ£¬6
 *  ÈôÎª5£¬ÕÒµ½6Ö®ºó½áÊø£¬·µ»ØÕÒ²»µ½
 *  
 *  »¹¿ÉÒÔ´Ó×óÏÂ½Ç³ö·¢£¬µ«ÊÇ²»ÄÜ´ÓÁíÍâÁ½¸ö½Ç³ö·¢
 *  
 *  ¾ÖÏÞ£ºÖ»ÄÜ´¦Àí·½Õó
 *
 */
public class Ch02_FindTwoDe {
	
	public static void main(String[] args) {
		//the num to find
		int x = 9;
		int[][] twoDeArr  = {
			{1,2,8,9},	
			{2,4,9,12},
			{4,7,10,13},
			{6,8,11,15}
		};
		
		String resLoc;
		
		resLoc = findLoc(twoDeArr,x);
		
		System.out.println(resLoc);
	}

	private static String findLoc(int[][] twoDeArr, int x) {
		
		int i = 0,j = twoDeArr.length-1;
		
		while (i < twoDeArr.length && j >= 0) {
			if (twoDeArr[i][j] < x) {
				i++;
				continue;
			}else if (twoDeArr[i][j] > x) {
				j--;
				continue;
			}else {
				return i+ " \t" + j;
			}			
		};
		
		return "Cant Find.";
	}

}
