emu in blogjava

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            171 隨筆 :: 103 文章 :: 1052 評論 :: 2 Trackbacks
          <2005年12月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          公告

          常用鏈接

          留言簿(92)

          隨筆分類(20)

          隨筆檔案(171)

          文章分類(89)

          文章檔案(103)

          相冊

          收藏夾(46)

          友情連接

          收藏

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          Problem Statement

               You are given a collection of music files that have each been tagged with the artist, album, track number, and song title. However, the actual file names do not follow any standard format. Given a desired naming format, determine the proper names for all of the files in the collection. You are given four String[]s, artists, albums, tracks, and titles, which contain the artist, album, track number, and song title, respectively, for all the music files. Element i of each String[] corresponds to the ith file. You are given the desired file name format as a String, format. This String will contain only characters from "ABTS -()._" (quotes for clarity only). To determine a file name, replace all occurrences of 'A', 'B', 'T', and 'S' in format with the artist, album, track number, and song title, respectively. All other characters should remain untouched. For example, if format = "A - B - T) S", the artist is "The Beatles", the album is "Rubber Soul", the track number is "07", and the song title is "Michelle", the file should be named "The Beatles - Rubber Soul - 07) Michelle". Return a String[] containing the file names for all the songs in the collection. The ith element of the return String[] should correspond to the song represented by the ith elements of the four String[] parameters.

          Definition

              
          Class: SongRenamer
          Method: rename
          Parameters: String[], String[], String[], String[], String
          Returns: String[]
          Method signature: String[] rename(String[] artists, String[] albums, String[] tracks, String[] titles, String format)
          (be sure your method is public)
              

          Constraints

          - artists, albums, tracks, and titles will each contain between 1 and 20 elements, inclusive.
          - artists, albums, tracks, and titles will each contain the same number of elements.
          - Each element of artists, albums, tracks, and titles will contain between 1 and 20 characters, inclusive.
          - Each element of artists, albums, tracks, and titles will contain only letters ('a'-'z', 'A'-'Z'), digits ('0'-'9'), and spaces.
          - format will contain between 1 and 10 characters, inclusive.
          - format will contain only characters from the String "ABTS -()._" (quotes for clarity only).

          Examples

          0)
              
          {"Marvin Gaye", "Marvin Gaye"}
          {"Here My Dear", "Whats Going On"}
          {"09", "7"}
          {"Annas Song", "Right On"}
          "A - B-T-S"
          Returns: 
          {"Marvin Gaye - Here My Dear-09-Annas Song",
           "Marvin Gaye - Whats Going On-7-Right On" }
          1)
              
          {"Booker T and the MGs"}
          {"McLemore Avenue"}
          {"Number Two"}
          {"Something"}
          "T. S_B_(S)"
          Returns: {"Number Two. Something_McLemore Avenue_(Something)" }
          format can contain multiple instances of the same tag. Also, track numbers do not have to contain only digits.
          2)
              
          {"The Beatles", "The Supremes", "YellowMatterCustard"}
          {"A Hard Days Night", "A Bit Of Liverpool", "One Night In NYC"}
          {"Twelve", "Siete", "7"}
          {"You Cant Do That", "You Cant Do That", "You Cant Do That"}
          "S (S) S"
          Returns: 
          {"You Cant Do That (You Cant Do That) You Cant Do That",
           "You Cant Do That (You Cant Do That) You Cant Do That",
           "You Cant Do That (You Cant Do That) You Cant Do That" }
          3)
              
          {"  The Leading Spaces"}
          {"  "}
          {"Trailing Space  "}
          {" s p a  c e s "}
          "S._A_B(T)"
          Returns: {" s p a  c e s ._  The Leading Spaces_  (Trailing Space  )" }
          Preserve all spaces.
          4)
              
          {"Ignored"}
          {"Unnoticed"}
          {"000"}
          {"Uncredited"}
          "()-(). "
          Returns: {"()-(). " }
          format doesn't necessarily have to contain any tags.

          This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

          posted on 2005-08-25 11:08 emu 閱讀(1634) 評論(3)  編輯  收藏 所屬分類: google編程大賽模擬題及入圍賽真題

          評論

          # re: SongRenamer (入圍賽250分真題) 2005-09-29 19:13 huangyi
          說說我的想法 .net的

          先使用string.replace,轉換format
          a->{0}, b->{1}, t->{2}, s->{3}

          然后就可以直接 filenames[i] = string.Format(formatString,artists[i], albums[i], tracks[i], ,titles[i]);

            回復  更多評論
            

          # 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);
          }
          }  回復  更多評論
            

          # emu的解法 2005-12-12 12:09 emu
          小飛俠,應該吧打印結果部分從函數中抽出來。
          我的解法是:

          public class SongRenamer
          {
          public String[] rename(String[] artists, String[] albums, String[] tracks, String[] titles, String format){
          String[] result = new String[artists.length];
          for(int i=0;i<result.length;i++){
          result[i] = format
          .replaceAll("A","\0\1")
          .replaceAll("B","\0\2")
          .replaceAll("T","\0\3")
          .replaceAll("S","\0\4")
          .replaceAll("\0\1",artists[i])
          .replaceAll("\0\2",albums[i])
          .replaceAll("\0\3",tracks[i])
          .replaceAll("\0\4",titles[i]);
          }
          return result;

          }
          public static void main(String[] args){
          SongRenamer s = new SongRenamer();
          String[] result = s.rename(
          new String[]{"Marvin Gaye", "Marvin Gaye"},
          new String[]{"Here My Dear", "Whats Going On"},
          new String[]{"09", "7"},
          new String[]{"Annas Song", "Right On"},
          "A - B-T-S");
          System.out.println(java.util.Arrays.asList(result));

          result = s.rename(
          new String[]{"The Beatles", "The Supremes", "YellowMatterCustard"},
          new String[]{"A Hard Days Night", "A Bit Of Liverpool", "One Night In NYC"},
          new String[]{"Twelve", "Siete", "7"},
          new String[]{"You Cant Do That", "You Cant Do That", "You Cant Do That"},
          "S (S) S");
          System.out.println(java.util.Arrays.asList(result));

          result = s.rename(
          new String[]{" The Leading Spaces"},
          new String[]{" "},
          new String[]{"Trailing Space "},
          new String[]{" s p a c e s "},
          "S._A_B(T");
          System.out.println(java.util.Arrays.asList(result));

          result = s.rename(
          new String[] {"Ignored"},
          new String[]{"Unnoticed"},
          new String[]{"000"},
          new String[]{"Uncredited"},
          "()-(). ");
          System.out.println(java.util.Arrays.asList(result));
          }
          }
            回復  更多評論
            

          主站蜘蛛池模板: 和政县| 云安县| 瓮安县| 贵德县| 张家川| 思茅市| 万全县| 社旗县| 安仁县| 军事| 延边| 青神县| 康乐县| 马尔康县| 谢通门县| 长海县| 那曲县| 耒阳市| 宝山区| 沛县| 鸡西市| 日土县| 渝北区| 长子县| 调兵山市| 萨嘎县| 宁安市| 兴海县| 翼城县| 海南省| 许昌县| 西丰县| 当涂县| 清镇市| 嘉义县| 共和县| 客服| 北辰区| 抚顺县| 化隆| 巴马|