我的評論

          re: 接口測試的兩種方法[未登錄] 小飛俠 2013-09-10 16:45  
          不錯的文章
          re: Java中文&編碼問題小結 小飛俠 2006-03-14 18:08  
          樓主總結的很全啊 看了以后感觸很深~~非常感謝!
          re: ImageLayers(入圍賽750分真題) 小飛俠 2005-12-12 11:49  
          哈,是的:)

          把自己的排序,改成Arrays.sort(split) :)

          嘻嘻,今天要比賽了,祝福各位,祝福emu, 也祝福我,小飛俠:)嘻嘻
          re: SongRenamer (入圍賽250分真題) 小飛俠 2005-12-11 22:35  
          public class test {
          public static String[] rename(String[] artists, String[] albums, String[] tracks, String[] titles, String format) {
          StringBuffer[] ret;
          String[] rets;
          int i, n, j;

          n = format.length();
          ret = new StringBuffer[artists.length];
          //初始化
          for (i = 0; i < ret.length; i++)
          ret[i] = new StringBuffer();

          for (j = 0; j < artists.length; j++) {
          for (i = 0; i < n; i++) {
          switch(format.charAt(i)) {
          case 'A' :
          ret[j].append(artists[j]);
          break;
          case 'B' :
          ret[j].append(albums[j]);
          break;
          case 'T' :
          ret[j].append(tracks[j]);
          break;
          case 'S' :
          ret[j].append(titles[j]);
          break;
          default :
          ret[j].append(format.charAt(i));
          break;
          }
          }
          }

          rets = new String[ret.length];
          for (i = 0; i < ret.length; i++) {
          rets[i] = ret[i].toString();
          }

          for (i = 0; i < rets.length; i++) {
          System.out.println(rets[i]);
          }

          return rets;
          }

          public static void main(String args[]) {
          String[] artists = {"Ignored"},
          albums = {"Unnoticed"},
          tracks = {"000"},
          titles = {"Uncredited"};
          String format = "()-(). ";

          rename(artists, albums, tracks, titles, format);
          }
          }
          re: ImageLayers(入圍賽750分真題) 小飛俠 2005-12-11 17:55  
          public class test {
          public static String[] content(String[] macro) {
          String[] mystr;
          int cur, i,j, n, begin, end;
          n = macro.length;
          cur = 0;
          mystr = new String[n];
          //第一步操作,獲取merge的String數組
          for (i = 0; i < n; i++) {
          if (macro[i].startsWith("OPEN")) {
          mystr[cur] = macro[i].substring(5);
          }

          if (macro[i].startsWith("MERGE")) {
          begin = Integer.parseInt(macro[i].substring(6, macro[i].indexOf("-")));
          end = Integer.parseInt(macro[i].substring(macro[i].indexOf("-")+1));

          //實現合并操作
          cur = begin;
          for (j = begin + 1; j <= end; j++) {
          mystr[cur] = mystr[cur].concat(" ").concat(mystr[j]);
          mystr[j] = null;
          }
          }
          cur++;
          }

          for (i = 0; i < n; i++) {
          System.out.println(mystr[i]);
          }

          //下面將原始的合并后的字符串數組,排序: 排序后,返回真正的數組
          mystr = sorts(mystr);

          System.out.println("sort ===");
          for (i = 0; i < mystr.length; i++) {
          System.out.println(mystr[i]);
          }

          return mystr;
          }

          public static String[] sorts(String[] mystr) {
          String[] ret;
          int i, j, n, cnt, cur=0;

          n = mystr.length;
          cnt = 0;

          //獲取實際的數組單元
          for(i = 0, n = mystr.length; i < n; i++) {
          if (mystr[i] != null)
          cnt++;

          }

          ret = new String[cnt];

          for (i = 0; i < n; i++) {
          //對單元進行排序
          if (mystr[i] != null) {
          ret[cur++] = sort(mystr[i]);
          }

          }


          System.out.println(cnt);
          return ret;
          }

          //單元排序, 最簡單的冒泡排序
          public static String sort(String str) {
          String[] a;
          int i, j,n, flag;
          String temp;

          if (str.indexOf(" ") < 0) {
          return str;
          }

          //開始排序
          a = str.split(" ");
          n = a.length;
          for (i = 1; i < n; i++) {
          flag = 0;
          for (j = 0; j < (n - i) ; j++) {
          if (a[j].compareTo(a[j+1]) > 0) {
          temp = a[j];
          a[j] = a[j+1];
          a[j+1] = temp;
          flag = 1;
          }
          }

          if (flag == 0) {
          break;
          }
          }

          //merge
          str = a[0];
          for (i = 1; i < n; i++) {
          str = str.concat(" ").concat(a[i]);
          }

          return str;
          }

          public static void main(String args[]) {
          String[] macro = {"OPEN sky",
          "OPEN clouds",
          "OPEN ground",
          "MERGE 0-1",
          "OPEN grass",
          "MERGE 0-2",
          "OPEN trees",
          "OPEN leaves",
          "OPEN birds",
          "MERGE 1-2",
          "MERGE 0-1"};

          content(macro);

          }
          }
          re: Crop(入圍賽250分真題) 小飛俠 2005-12-11 17:52  
          public class test {
          public static String[] crop(String[] image, String[] crops) {
          String[] result, crop;
          int row0, row1, col0, col1, x0, y0, x1, y1, n, i;

          row0 = col0 = 0;
          row1 = image.length - 1;
          col1 = image[0].length() - 1;
          for (i = 0, n = crops.length; i < n; i++) {
          crop = crops[i].split(" ");
          x0 = Integer.parseInt(crop[0]);
          y0 = Integer.parseInt(crop[1]);
          x1 = Integer.parseInt(crop[2]);
          y1 = Integer.parseInt(crop[3]);

          //邊界判斷
          if (x0 < 0 || x0 > x1 || x1 > row1)
          continue;
          if (y0 < 0 || y0 > y1 || y1 > col1)
          continue;

          row1 = row0 + x1;
          col1 = col0 + y1;
          row0 += x0;
          col0 += y0;

          }

          //輸出
          result = new String[row1 - row0 + 1];
          for (i = 0, n = result.length; i < n ; i++) {
          result[i] = image[i+row0].substring(col0, col1+1);
          }

          for (i = 0, n = result.length; i < n ; i++) {
          System.out.println(result[i]);
          }
          return result;
          }

          public static void main(String args[]) {
          String[] image, crops, result;

          image = new String[4];
          crops = new String[2];

          image[0] = new String("X.X.X.X.X.X.X.X");
          image[1] = new String(".X.X.X.X.X.X.X.");
          image[2] = new String(".X.X.X.X.X.X.X.");
          image[3] = new String("X.X.X.X.X.X.X.X");


          crops[0] = new String("1 1 2 3");
          crops[1] = new String("0 0 1 1");

          crop(image, crops);

          }

          }
          re: HouseParty(賽前模擬題) 小飛俠 2005-12-10 17:48  
          以上僅僅是按照自己的想法,做了一個大概的程序流程,尚未進行任何優化,但是思想很簡單, 首先遵循三個原則, 門最大使用度,窗最大使用度, 盡可能接近正方形. 然后,在約束條件和三大原則的指導下,先初始化房子(即可能的最小面積),之后,根據剩下的原始材料進行添窗加墻. 最后剩下的就是無法使用的材料.

          其實,這個方法還是很麻煩,如果不需要考慮房子怎么建造,而僅僅是需要一個最大面積,還有有更簡單的方法, 思想就是,只要滿足約束條件,剔除多余的原材料,剩下的都是等單元,將剩下的所有,管他是門是窗是墻,加起來,求一個盡可能正方的結果,完.

          re: HouseParty(賽前模擬題) 小飛俠 2005-12-10 17:34  
          //--接上
          public static int getArea(int x, int y) {
          return x * y;
          }

          public static int maxArea(int wall, int window, int door) {
          int[] res = new int[3];
          StringBuffer[] room;
          int i, j;

          System.out.println("總材料, wall="+wall+";window"+window+";door"+door);

          if (door > 4) door = 4;
          res[0] = wall;
          res[1] = window;
          res[2] = door;

          if (door == 0) {
          System.out.println("Room can not be inited");
          return 0;
          }

          //第一步,初始化房間,原則盡可能多的使用門.
          room = initRoom(res);

          if (room[0].length() == 0) {
          System.out.println("Room can not be inited");
          return 0;
          }

          //測試初始化情況,輸出圖形,和輸出剩下的元素.
          System.out.println("初始化房子:");
          for(i=0; i < 4; i++) {
          System.out.println(room[i]);
          }
          System.out.println("剩余的材料:");
          System.out.println("wall="+res[0]);
          System.out.println("window="+res[1]);
          System.out.println("door="+res[2]);


          //第二步,初始化成功后,開始有條件約束的添加窗和門.
          if (res[0] < 2 ) {
          return getArea(room[0].length(), room[1].length());
          }

          //獲取當前條件下,能使用的窗的總數,
          if (res[1] > 0) {
          if ( res[1] % 2 == 0 ) {
          //如果窗戶是偶數
          if (res[0] < res[1]) {
          res[1] = res[0];
          }
          } else {
          //如果窗戶是奇數
          if (res[0] < res[1] + 2) {
          res[1] = res[0] - 2;
          }
          }
          }


          //獲取了能使用的窗總數后,判斷現在的窗的奇偶.
          j = room[0].length() >= room[1].length() ? 1 : 0;
          if (res[1] % 2 == 0){
          while(res[1] > 0 && res[0] >= 2) {
          room[j].append("W-");
          room[j+2].append("W-");
          res[0] -= 2;
          res[1] -= 2;
          j = 1 - j;
          }
          } else {
          while(res[1] > 1 && res[0] >= 2) {
          room[j].append("W-");
          room[j+2].append("W-");
          res[0] -= 2;
          res[1] -= 2;
          j = 1 - j;
          }
          //余一
          if (res[0] >= 3) {
          room[j].append("W-");
          room[j+2].append("--");
          res[0] -= 3;
          res[1] -= 1;
          j = 1 - j;
          }
          }

          //最后,如果剩余的墻,按照偶數個添加.
          if (res[0] % 2 == 0){
          while(res[0] > 0) {
          room[j].append("-");
          room[j+2].append("-");
          res[0] -= 2;
          j = 1 - j;
          }
          } else {
          while(res[0] > 1) {
          room[j].append("-");
          room[j+2].append("-");
          res[0] -= 2;
          j = 1 - j;
          }
          //余一, 不處理

          }


          //測試初始化情況,輸出圖形,和輸出剩下的元素.
          for(i=0; i < 4; i++) {
          System.out.println(room[i]);
          }
          System.out.println("剩余的材料:");
          System.out.println("wall="+res[0]);
          System.out.println("window="+res[1]);
          System.out.println("door="+res[2]);


          return getArea(room[0].length(), room[1].length());
          }

          public static void main(String args[]) {
          int wall, door, window, mymax;

          wall = 6;
          window = 23;
          door = 13;
          mymax = maxArea(wall, window, door);

          System.out.println("最大面積="+mymax);
          }
          }

          re: HouseParty(賽前模擬題) 小飛俠 2005-12-10 17:33  
          public class test {
          //初始化房間,扣除使用的原材料,返回初始化房間數組
          public static StringBuffer[] initRoom(int bres[]) {
          StringBuffer[] myroom = new StringBuffer[4];

          //數組內元素的初始化
          myroom[0] = new StringBuffer();
          myroom[1] = new StringBuffer();
          myroom[2] = new StringBuffer();
          myroom[3] = new StringBuffer();

          if (bres[2] == 4) {
          if (bres[0] >= 8) {
          //初始化4個門的room
          myroom[0].append("-D-");
          myroom[1].append("-D-");
          myroom[2].append("-D-");
          myroom[3].append("-D-");
          bres[0] -= 8;
          bres[2] -= 4;
          return myroom;
          }
          }

          if (bres[2] >= 3) {
          if (bres[1] >= 1) {
          if (bres[0] >= 8) {
          //初始化3個門的room
          myroom[0].append("-D-");
          myroom[1].append("-D-");
          myroom[2].append("-D-");
          myroom[3].append("-W-");
          bres[0] -= 8;
          bres[1] -= 1;
          bres[2] -= 3;
          return myroom;
          }
          } else {
          if (bres[0] >= 9) {
          myroom[0].append("-D-");
          myroom[1].append("-D-");
          myroom[2].append("-D-");
          myroom[3].append("---");
          bres[0] -= 9;
          bres[2] -= 3;
          return myroom;
          }
          }
          }

          if (bres[2] >= 2) {
          if (bres[0] >= 6) {
          //初始化4個門的room
          myroom[0].append("-D-");
          myroom[1].append("-");
          myroom[2].append("-D-");
          myroom[3].append("-");
          bres[0] -= 6;
          bres[2] -= 2;
          return myroom;
          }
          }

          if (bres[2] >= 1) {
          if (bres[1] >= 1) {
          if (bres[0] >= 6) {
          //初始化3個門的room
          myroom[0].append("-D-");
          myroom[1].append("-");
          myroom[2].append("-W-");
          myroom[3].append("-");
          bres[0] -= 6;
          bres[1] -= 1;
          bres[2] -= 1;
          return myroom;
          }
          } else {
          if (bres[0] >= 7) {
          myroom[0].append("-D-");
          myroom[1].append("-");
          myroom[2].append("---");
          myroom[3].append("-");
          bres[0] -= 7;
          bres[2] -= 1;
          return myroom;
          }
          }
          }

          return myroom;
          }

          -->>未完待續
          public class CursorPosition {
          public static int getPosition(String commonds, int ncount) {
          //獲取開始查詢的位置
          int fromIndex1, fromIndex2, fromIndex, position;

          fromIndex1 = commonds.lastIndexOf((int)'E');
          fromIndex2 = commonds.lastIndexOf((int)'H');
          if (fromIndex1 > fromIndex2) {
          fromIndex = fromIndex1 >0 ? fromIndex1 : 0;
          position = ncount;
          } else {
          fromIndex = fromIndex2 > 0 ? fromIndex2 : 0;
          position = 0;
          }

          //取字符串的字符,開始進行統計
          for (int i = fromIndex + 1; i < commonds.length(); i++) {
          System.out.println(commonds.charAt(i));
          switch(commonds.charAt(i)) {
          case 'L' :
          position = (position == 0) ? 0 : --position;
          break;
          case 'R' :
          position = (position == ncount) ? ncount : ++position;
          break;
          default :
          break;
          }
          }

          return position;
          }
          }
          public class MatrixTool{
          public String[] convert(String s) {
          int slen, col;
          slen = s.length();
          col = (int)Math.sqrt(slen);
          if ( slen % col != 0) {
          String[] ret = new String[0];
          return ret;
          }

          String[] ret = new String[col];
          for (int i = 0; i < col; i++) {
          ret[i] = s.substring(i*col, (i+1)*col);
          }

          return ret;
          }
          }

          posts - 2, comments - 1, trackbacks - 0, articles - 2

          Copyright © 小飛俠

          主站蜘蛛池模板: 灵寿县| 山丹县| 郸城县| 潜山县| 济南市| 革吉县| 舞钢市| 大理市| 根河市| 乐陵市| 汝城县| 天祝| 泗洪县| 磐石市| 海阳市| 鄂州市| 宾阳县| 静海县| 兴隆县| 米泉市| 米林县| 铜鼓县| 隆尧县| 册亨县| 金门县| 阿尔山市| 霍城县| 屏山县| 滨海县| 新田县| 肇源县| 澄江县| 沂南县| 墨脱县| 龙井市| 义马市| 同德县| 历史| 和平区| 鸡东县| 高邮市|