我的評論
re: 驚嘆女媧造人--娛談系統設計 emu 2006-02-11 22:59
原來是女媧,我還一直以為是上帝造的人呢。
從現實的角度看,人是進化出來的,我認為從進化這個角度上來看軟件設計,會別有一翻風景。
從現實的角度看,人是進化出來的,我認為從進化這個角度上來看軟件設計,會別有一翻風景。
re: tomcat 不同版本的運行速度 emu 2006-02-11 22:48
呵呵你沒有看清楚我的測試數據,第一項就是線程數啊,也就是模擬的并發訪問的用戶數。我分別測試了10個,20個,30個,50個和100個并發線程訪問的情況,最后一個情況也就是你說的100*100啊。
一般我們配置tomcat的時候連接數也就是設5~20個左右,tomcat也不是很適合用于更高壓力的情形(20個線程通常已經足夠支撐三位數的同時在線用戶了)。雖然jmeter開1000個線程一點問題都沒有,但是通常我做的程序不需要面對這么大的壓力了。
我只是在比較相同情形下三個不同版本的tomcat的速度而已,我覺得結果已經夠說明問題了。
一般我們配置tomcat的時候連接數也就是設5~20個左右,tomcat也不是很適合用于更高壓力的情形(20個線程通常已經足夠支撐三位數的同時在線用戶了)。雖然jmeter開1000個線程一點問題都沒有,但是通常我做的程序不需要面對這么大的壓力了。
我只是在比較相同情形下三個不同版本的tomcat的速度而已,我覺得結果已經夠說明問題了。
re: tomcat 不同版本的運行速度 emu 2006-02-11 22:40
呵呵你沒有看清楚我的測試數據,第一項就是線程數啊,也就是模擬的并發訪問的用戶數。我分別測試了10個,20個,30個,50個和100個并發線程訪問的情況,最后一個情況也就是你說的100*100啊。
一般我們配置tomcat的時候連接數也就是設5~20個左右,tomcat也不是很適合用于更高壓力的情形(20個線程通常已經足夠支撐三位數的同時在線用戶了)。
我只是在比較相同情形下三個不同版本的tomcat的速度而已,我覺得結果已經夠說明問題了。
一般我們配置tomcat的時候連接數也就是設5~20個左右,tomcat也不是很適合用于更高壓力的情形(20個線程通常已經足夠支撐三位數的同時在線用戶了)。
我只是在比較相同情形下三個不同版本的tomcat的速度而已,我覺得結果已經夠說明問題了。
re: AJAX案例研究之 google reader emu 2006-02-09 23:27
呵呵,這只是篇個人的blog而已,你以為作者在寫史記還是纂春秋呢?
re: java版本的escape和unescape函數 emu 2006-02-08 12:30
官方版本的標準類庫也是人寫的。除非在虛擬機內部提供支持,否則他恐怕也只能做到這樣了。
re: 一個Ajax實現的聯機游戲 emu 2006-02-03 12:48
稍微優化了一下。點擊這里下載優化后的版本。
re: Ajax還是Ajah,這是個問題 emu 2006-02-02 15:40
因為你沒有把文件用一個http服務器發布出來。
xmlhttprequest不能訪問本地文件系統,需要建立http連接才可以。
xmlhttprequest不能訪問本地文件系統,需要建立http連接才可以。
re: Ajax 裸奔之一 emu 2006-01-26 17:09
淺顯易懂是我寫這寫文章的一個關鍵目標。
re: google code jam china 入圍賽排名 emu 2006-01-26 17:09
ACM的高手可能都忙著培訓做題去了吧。
re: perl初用感覺 emu 2006-01-26 13:03
日本人的技術也是技術。技術不分國界??茖W家可以劃分政治陣營,科學不可以。
以前看《果殼中的宇宙》提到蘇聯科學家的一些荒唐往事,覺得蘇聯人也太狹隘了,為什么社會主義的科學就一定要比資本主義的好呢。
以前看《果殼中的宇宙》提到蘇聯科學家的一些荒唐往事,覺得蘇聯人也太狹隘了,為什么社會主義的科學就一定要比資本主義的好呢。
re: DiskDefrag(賽前模擬題) emu 2006-01-25 17:34
能做到2^12種狀態就好了。我分析的結果是12!種狀態阿,比2^12多了十萬倍以上。
re: AJAX案例研究之Gmail emu 2006-01-25 17:26
終于盼到duduwolf來留言了,榮幸榮幸。
我在你的blog上留過言,加過你的msn,幾次想要聯系你都未能如愿,能否留個有效的聯系方式?有不少問題想和你討論。
我認為肯定是某種js加工工具,但不是混淆器。再簡單的混淆器出來的代碼也是一塌糊涂的,google用的工具的加工目的僅僅是壓縮文件尺寸,并沒有刻意的降低可讀性。
google的幾個應用針對性很強,用AJaH方式顯然是非常合適的。我一直想強調的是,我們做系統不可以照抄google的方式,要多在可維護性和通用性上想問題,不要放任系統變的太專用、耦合變的太強、軟件變的太“硬”。
我在你的blog上留過言,加過你的msn,幾次想要聯系你都未能如愿,能否留個有效的聯系方式?有不少問題想和你討論。
我認為肯定是某種js加工工具,但不是混淆器。再簡單的混淆器出來的代碼也是一塌糊涂的,google用的工具的加工目的僅僅是壓縮文件尺寸,并沒有刻意的降低可讀性。
google的幾個應用針對性很強,用AJaH方式顯然是非常合適的。我一直想強調的是,我們做系統不可以照抄google的方式,要多在可維護性和通用性上想問題,不要放任系統變的太專用、耦合變的太強、軟件變的太“硬”。
re: 今天給兄弟部門總結的幾點關于ajax的建議,公開出來分享一下。 emu 2006-01-24 12:10
從來沒有遇到過這個問題,估計是你用了同步方式發送數據造成的,試試改用異步回調方式來解決這個問題。
re: 為什么一定要看《無極》 emu 2006-01-22 23:29
re: 仿寫了一個游戲 emu 2006-01-18 09:31
直接拷貝代碼下來不能運行,是因為這一行:
<style>b{position:absolute;cursor:hand;font-size:20}</style>
從上面拷貝下來的時候居然變成:
<style>b{}{position:absolute;cursor:hand;font-size:20}</style>
這是代碼展示器的一個bug了,自己改回來就好了。
<style>b{position:absolute;cursor:hand;font-size:20}</style>
從上面拷貝下來的時候居然變成:
<style>b{}{position:absolute;cursor:hand;font-size:20}</style>
這是代碼展示器的一個bug了,自己改回來就好了。
re: 仿寫了一個游戲 emu 2006-01-18 09:24
MFF屏蔽不了。
其實按照原游戲的效果,這些字母都應該是gif圖片做的,本來就不存在選中問題。
不過寫程序純粹為了好玩,沒花那么多時間來做這些細節,只是隨便放些字母上去。
其實按照原游戲的效果,這些字母都應該是gif圖片做的,本來就不存在選中問題。
不過寫程序純粹為了好玩,沒花那么多時間來做這些細節,只是隨便放些字母上去。
re: 今天給兄弟部門總結的幾點關于ajax的建議,公開出來分享一下。 emu 2006-01-16 13:46
瀏覽器出于安全考慮限制了來自不同域的頁面不能相互訪問頁面內容,也限制了xmlhttp控件不能訪問其他域的xml資源。如果你沒有遇到這個問題的話,那么對你可能并不是問題。
re: 今天給兄弟部門總結的幾點關于ajax的建議,公開出來分享一下。 emu 2006-01-13 22:06
冒大哥提到了編碼問題,eamoi 前陣子好像也在頭疼?
這個問題上我的建議是根本上回避這個問題,否則怎么解決都是很麻煩的事情。
這個問題上我的建議是根本上回避這個問題,否則怎么解決都是很麻煩的事情。
re: 見識了一下ajax高手風范 emu 2006-01-13 21:55
樓上是冒志鴻大哥啊,久仰久仰!
re: 今天給兄弟部門總結的幾點關于ajax的建議,公開出來分享一下。 emu 2006-01-13 21:49
myy:
比如,服務端返回:
<ul>
<li>aaa</li>
<li>bbb</li>
<li>ccc</li>
</ul>
這樣的數據,很多情況下,放到頁面中就可以顯示了,如果不符合要求,用xml也能解析重新組織。而不是自己重新定義一套tag
我很懷疑你有沒有實踐經驗了。一般情況下我們數據顯示到頁面上都會帶上css樣式的,同樣的數據的不同的頁面上往往都使用不同的樣式。
至于再刻意去把xhtml按照xml去解析,完全就失去了xml的“自說明性”的優點了。有一天別人來維護你的代碼的時候,怎么猜得出你的數據表達的是這個意思呢:
<userlist>
<user>aaa</user>
<user>bbb</user>
<user>ccc</user>
</userlist>
比如,服務端返回:
<ul>
<li>aaa</li>
<li>bbb</li>
<li>ccc</li>
</ul>
這樣的數據,很多情況下,放到頁面中就可以顯示了,如果不符合要求,用xml也能解析重新組織。而不是自己重新定義一套tag
我很懷疑你有沒有實踐經驗了。一般情況下我們數據顯示到頁面上都會帶上css樣式的,同樣的數據的不同的頁面上往往都使用不同的樣式。
至于再刻意去把xhtml按照xml去解析,完全就失去了xml的“自說明性”的優點了。有一天別人來維護你的代碼的時候,怎么猜得出你的數據表達的是這個意思呢:
<userlist>
<user>aaa</user>
<user>bbb</user>
<user>ccc</user>
</userlist>
re: 今天給兄弟部門總結的幾點關于ajax的建議,公開出來分享一下。 emu 2006-01-12 18:16
如果AJAH只適合簡單的情況,而AJAX則全都適合,那么為什么要用AJAH呢?
re: java版本的escape和unescape函數 emu 2006-01-06 22:18
樓上說的是否是 java.net.URLDecoder / java.net.URLEncoder
這兩個方法對應的是javascript的 encodeURI/decodeURI 和 encodeURIComponent/decodeURIComponent 吧?
我寫的兩個方法對應的是javascript 的escape/unescape
這兩個方法對應的是javascript的 encodeURI/decodeURI 和 encodeURIComponent/decodeURIComponent 吧?
我寫的兩個方法對應的是javascript 的escape/unescape
越扯越遠了 emu 2006-01-04 19:54
轉載要忠實,不要夾私貨
re: DiskDefrag(賽前模擬題) emu 2005-12-28 18:57
用動態規劃?具體怎么做呢?
cheapwine是judgeonline過來的啊?
cheapwine是judgeonline過來的啊?
re: 致歉 emu 2005-12-27 13:09
這段時間好像問題比較多哦。
re: google code jam round2 排名 emu 2005-12-25 23:13
我覺得具體的java話題當然很重要,算法和數據結構這樣的基礎也不可忽略,google code jam這樣的賽事blogjava關注的人太少了,所以放到首頁上吸引一下眼球而已。如果大家真的不感興趣就算了,勉強不來的。
re: google中國編程挑戰賽入圍賽真題 -- HardDuplicateRemover(1000分) emu 2005-12-22 18:38
又是自己做排序啊?
re: google中國編程挑戰賽資格賽真題 -- PlayCards emu 2005-12-22 17:36
就是首先生成所有可能的set和run,然后嘗試所有run和set的組合,看看那個符合要求啊。
re: google中國編程挑戰賽入圍賽真題 -- BlockStructure(500分) emu 2005-12-21 14:06
我覺得這組解是干擾數據:
{2,2,2,4,4}
Returns: 2
We can use a 3x2 rectangle and a 2x4 rectangle.
××
××
×××××
×××××
如果題目提供的解是這樣:
××
××
×××××
×××××
答案就容易找的多了。
{2,2,2,4,4}
Returns: 2
We can use a 3x2 rectangle and a 2x4 rectangle.
××
××
×××××
×××××
如果題目提供的解是這樣:
××
××
×××××
×××××
答案就容易找的多了。
re: google中國編程挑戰賽入圍賽真題 -- HardDuplicateRemover(1000分) emu 2005-12-21 13:42
參賽就可以copy題目出來了。
確實是有一點點變態的,我需要超過一個鐘頭來做這一道題。 emu 2005-12-19 18:28
一個鐘頭要求做這么變態一道題再加一道小題,要求確實高了一點。不知道有多少高手得分?
import java.util.ArrayList;
public class PlayCards {
public int maxCards(String[] cards){
//S=0 H=1 D=2 C=3
int[][] map = new int[11][4];
for(int i=0;i<cards.length;i++){
String[] t = cards[i].split(" ");
int t0 = Integer.parseInt(t[0],10)-1;
int t1=0;
if(t[1].equals("H")) t1=1;
else if(t[1].equals("D")) t1=2;
else if(t[1].equals("C")) t1=3;
map[t0][t1]=1;
}
/*
for(int i=0;i<11;i++){
for(int j=0;j<4;j++)
System.out.print(map[i][j]+" ");
System.out.println();
}
*/
ArrayList sets = new ArrayList();
ArrayList set,run;
for(int i=0;i<11;i++){
int c = map[i][0]+map[i][1]+map[i][2]+map[i][3];
if(c==3){
set = new ArrayList();
for(int j=0;j<4;j++) if(map[i][j]>0) set.add(new int[]{i,j});
sets.add(set);
}else if (c==4){
set = new ArrayList();
for(int j=0;j<4;j++) set.add(new int[]{i,j});
sets.add(set);
for(int j=0;j<4;j++){
set = new ArrayList();
for(int k=0;k<4;k++) if(j!=k) set.add(new int[]{i,k});
sets.add(set);
}
}
}
for(int i=0;i<4;i++){
for(int j=0;j<8;j++){
for(int k=j;k<11;k++){
if(map[k][i]<1) break;
if(k-j<2) continue;
run = new ArrayList();
for(int t=j;t<=k;t++)
run.add(new int[]{t,i});
sets.add(run);
}
}
}
int max = 0;
for(int i=0,n=1<<sets.size();i<n;i++){
if(checkConflic(sets,i)){
int m = countCards(sets,i);
if(max<m) max=m;
}
}
return max;
}
private boolean checkConflic(ArrayList sets,int status){
boolean[][] map = new boolean[11][4];
for(int i=0,n=sets.size();i<n;i++){
if((status & (1<<i))==0) continue;
ArrayList set = (ArrayList)sets.get(i);
for(int j=0,m=set.size();j<m;j++){
int[] card = (int[])set.get(j);
if(map[card[0]][card[1]])return false;
map[card[0]][card[1]]=true;
}
}
return true;
}
private int countCards(ArrayList sets,int status){
int result =0;
for(int i=0,n=sets.size();i<n;i++){
if((status & (1<<i))==0) continue;
ArrayList set = (ArrayList)sets.get(i);
result += set.size();
}
return result;
}
public static void main(String[] args)
{
PlayCards p = new PlayCards();
System.out.println(p.maxCards(new String[]{"1 S", "2 S", "3 S"}));
System.out.println(p.maxCards(new String[]{"4 C", "4 D", "4 S", "3 S", "2 S"}));
System.out.println(p.maxCards(new String[]{"1 S", "2 S"}));
System.out.println(p.maxCards(new String[]{"1 S", "2 S", "10 S", "5 S", "8 S",
"3 H", "9 H", "6 H", "5 H", "4 H",
"10 D", "5 D", "7 D", "4 D", "1 D",
"2 C", "4 C", "5 C", "6 C", "7 C"}
));
}
}
import java.util.ArrayList;
public class PlayCards {
public int maxCards(String[] cards){
//S=0 H=1 D=2 C=3
int[][] map = new int[11][4];
for(int i=0;i<cards.length;i++){
String[] t = cards[i].split(" ");
int t0 = Integer.parseInt(t[0],10)-1;
int t1=0;
if(t[1].equals("H")) t1=1;
else if(t[1].equals("D")) t1=2;
else if(t[1].equals("C")) t1=3;
map[t0][t1]=1;
}
/*
for(int i=0;i<11;i++){
for(int j=0;j<4;j++)
System.out.print(map[i][j]+" ");
System.out.println();
}
*/
ArrayList sets = new ArrayList();
ArrayList set,run;
for(int i=0;i<11;i++){
int c = map[i][0]+map[i][1]+map[i][2]+map[i][3];
if(c==3){
set = new ArrayList();
for(int j=0;j<4;j++) if(map[i][j]>0) set.add(new int[]{i,j});
sets.add(set);
}else if (c==4){
set = new ArrayList();
for(int j=0;j<4;j++) set.add(new int[]{i,j});
sets.add(set);
for(int j=0;j<4;j++){
set = new ArrayList();
for(int k=0;k<4;k++) if(j!=k) set.add(new int[]{i,k});
sets.add(set);
}
}
}
for(int i=0;i<4;i++){
for(int j=0;j<8;j++){
for(int k=j;k<11;k++){
if(map[k][i]<1) break;
if(k-j<2) continue;
run = new ArrayList();
for(int t=j;t<=k;t++)
run.add(new int[]{t,i});
sets.add(run);
}
}
}
int max = 0;
for(int i=0,n=1<<sets.size();i<n;i++){
if(checkConflic(sets,i)){
int m = countCards(sets,i);
if(max<m) max=m;
}
}
return max;
}
private boolean checkConflic(ArrayList sets,int status){
boolean[][] map = new boolean[11][4];
for(int i=0,n=sets.size();i<n;i++){
if((status & (1<<i))==0) continue;
ArrayList set = (ArrayList)sets.get(i);
for(int j=0,m=set.size();j<m;j++){
int[] card = (int[])set.get(j);
if(map[card[0]][card[1]])return false;
map[card[0]][card[1]]=true;
}
}
return true;
}
private int countCards(ArrayList sets,int status){
int result =0;
for(int i=0,n=sets.size();i<n;i++){
if((status & (1<<i))==0) continue;
ArrayList set = (ArrayList)sets.get(i);
result += set.size();
}
return result;
}
public static void main(String[] args)
{
PlayCards p = new PlayCards();
System.out.println(p.maxCards(new String[]{"1 S", "2 S", "3 S"}));
System.out.println(p.maxCards(new String[]{"4 C", "4 D", "4 S", "3 S", "2 S"}));
System.out.println(p.maxCards(new String[]{"1 S", "2 S"}));
System.out.println(p.maxCards(new String[]{"1 S", "2 S", "10 S", "5 S", "8 S",
"3 H", "9 H", "6 H", "5 H", "4 H",
"10 D", "5 D", "7 D", "4 D", "1 D",
"2 C", "4 C", "5 C", "6 C", "7 C"}
));
}
}
re: google中國編程挑戰賽資格賽真題 -- WordPath(750分) emu 2005-12-17 01:12
你的解法倒是很別出心裁,有必要一定要倒過來查嗎,正著查不是一樣?
不過看看代碼量,估計是超過1個小時的。
不過看看代碼量,估計是超過1個小時的。
re: google中國編程挑戰賽資格賽真題 -- PlayCards emu 2005-12-16 15:35
飯要一口一口吃的,先把數據結構和算法的教科書啃通了再來做吧。
re: 敗走google編程大賽 emu 2005-12-16 11:20
拜托,這是8月份的帖子,講的是東亞code jam的事了。
今天早上收到的是:
emu,
恭喜您!Google Code Jam - 中國編程挑戰賽資格賽的官方結果已經公布。我們很高興地通知您:您已經晉級第一輪。這是一個很大的成就。
Google? Code Jam –中國編程挑戰賽第一輪將于北京時間12月19日星期一晚9點通過網絡在線舉行。參加第一輪比賽需要注冊。注冊在比賽當天從北京時間18:00開始到20:55結束。請按如下步驟注冊:登錄競技場,點擊“Active Contests”(現行比賽)菜單選項,選擇“Round One”(第一輪),然后選擇“Register”(注冊)。
在所有參加第一輪比賽的500名參賽者中,最多250名將會晉級第二輪。第二輪是最后一輪通過網絡在線舉行的比賽。第二輪比賽將于12月22日星期四舉行。
我們建議您在參加第一輪比賽之前閱讀競賽說明。競賽說明可以在下面網頁中找到: http://www.topcoder.com/pl/?module=Static&d1=gccj05&d2=ZH_instructions
此外,請注意我們不久后會再發送一封含有有關第一輪比賽重要信息的后續電子郵件。
再一次恭喜您在資格賽中勝出。
- Google Code Jam 團隊
www.topcoder.com, TopCoder, Inc., 703 Hebron Avenue, Glastonbury, CT 06033, 電話:1-866-867-2633
******************************************************
Congratulations! The results of the Google Code Jam China Qualification Round have been officially tabulated and we're happy to announce that you have advanced to Round 1. This is a great accomplishment!
Round 1 of Google(TM) Code Jam China will take place online at 21:00 GMT +8 on Monday, December 19th. Registration is required for this round and will be open from 18:00 to 20:55 GMT +8 on the day of the event. In order to register for the round: Login to the competition arena, click on the "Active Contests" menu item, select Round One, and select "Register".
Of the 500 people participating, up to 250 competitors will advance to Round 2, the final online round, which takes place on Thursday, December 22nd.
We suggest that you read through the instructions prior to competing in Round 1. You can find them here: http://www.topcoder.com/pl/?module=Static&d1=gccj05&d2=EN_instructions
Also, please note that we will follow-up with an additional email shortly, which will include important information regarding Round 1.
Congratulations again on making it through the qualification round!
- The Google Code Jam Team
www.topcoder.com, TopCoder, Inc., 703 Hebron Avenue, Glastonbury, CT 06033, Phone: 1-866-867-2633
今天早上收到的是:
emu,
恭喜您!Google Code Jam - 中國編程挑戰賽資格賽的官方結果已經公布。我們很高興地通知您:您已經晉級第一輪。這是一個很大的成就。
Google? Code Jam –中國編程挑戰賽第一輪將于北京時間12月19日星期一晚9點通過網絡在線舉行。參加第一輪比賽需要注冊。注冊在比賽當天從北京時間18:00開始到20:55結束。請按如下步驟注冊:登錄競技場,點擊“Active Contests”(現行比賽)菜單選項,選擇“Round One”(第一輪),然后選擇“Register”(注冊)。
在所有參加第一輪比賽的500名參賽者中,最多250名將會晉級第二輪。第二輪是最后一輪通過網絡在線舉行的比賽。第二輪比賽將于12月22日星期四舉行。
我們建議您在參加第一輪比賽之前閱讀競賽說明。競賽說明可以在下面網頁中找到: http://www.topcoder.com/pl/?module=Static&d1=gccj05&d2=ZH_instructions
此外,請注意我們不久后會再發送一封含有有關第一輪比賽重要信息的后續電子郵件。
再一次恭喜您在資格賽中勝出。
- Google Code Jam 團隊
www.topcoder.com, TopCoder, Inc., 703 Hebron Avenue, Glastonbury, CT 06033, 電話:1-866-867-2633
******************************************************
Congratulations! The results of the Google Code Jam China Qualification Round have been officially tabulated and we're happy to announce that you have advanced to Round 1. This is a great accomplishment!
Round 1 of Google(TM) Code Jam China will take place online at 21:00 GMT +8 on Monday, December 19th. Registration is required for this round and will be open from 18:00 to 20:55 GMT +8 on the day of the event. In order to register for the round: Login to the competition arena, click on the "Active Contests" menu item, select Round One, and select "Register".
Of the 500 people participating, up to 250 competitors will advance to Round 2, the final online round, which takes place on Thursday, December 22nd.
We suggest that you read through the instructions prior to competing in Round 1. You can find them here: http://www.topcoder.com/pl/?module=Static&d1=gccj05&d2=EN_instructions
Also, please note that we will follow-up with an additional email shortly, which will include important information regarding Round 1.
Congratulations again on making it through the qualification round!
- The Google Code Jam Team
www.topcoder.com, TopCoder, Inc., 703 Hebron Avenue, Glastonbury, CT 06033, Phone: 1-866-867-2633
re: google中國編程挑戰賽資格賽真題 -- PlayCards emu 2005-12-16 11:00
這個還真有點不好搞的,我一個鐘頭搞不定。周末看看有沒有時間研究了。
re: google中國編程挑戰賽資格賽真題 -- WordPath(750分) emu 2005-12-15 15:52
試試更大的測試數據:
public class WordPath {
public long countPaths(String[] grid, String find){
int rowCount = grid.length;
int cellCount=grid[0].length();
char[][] charGrid = new char[rowCount][cellCount];
long[][] m = new long[rowCount][cellCount],m1 = new long[rowCount][cellCount];
for(int y=0;y<rowCount;y++)
for(int x=0;x<cellCount;x++)
if (find.charAt(0)==(charGrid[y][x]=grid[y].charAt(x))) m[y][x]=1;
for(int i=1;i<find.length();i++){
char ch = find.charAt(i);
for(int y=0;y<rowCount;y++){
for(int x=0;x<cellCount;x++){
if(ch == charGrid[y][x]){
if(y>0){
if(x>0)m1[y][x]+=m[y-1][x-1];
m1[y][x]+=m[y-1][x];
if(x<cellCount-1) m1[y][x]+=m[y-1][x+1];
}
if(x>0)m1[y][x]+=m[y][x-1];
if(x<cellCount-1) m1[y][x]+=m[y][x+1];
if(y<rowCount-1){
if(x>0) m1[y][x]+=m[y+1][x-1];
m1[y][x]+=m[y+1][x];
if(x<cellCount-1) m1[y][x]+=m[y+1][x+1];
}
}
}
}
m=m1;m1= new long[rowCount][cellCount];
}
long result = 0;
for(int i=0;i<rowCount;i++)for(int j=0;j<cellCount;j++) if(m[i][j]<0||(result += m[i][j])<0)return -1;
return result;
}
public static void main(String[] args){
WordPath w = new WordPath();
System.out.println(w.countPaths(new String[]{"ABC","FED","GHI"},"ABCDEFGHI"));
System.out.println(w.countPaths(new String[]{"ABC","FED","GAI"},"ABCDEA"));
System.out.println(w.countPaths(new String[]{"ABC","DEF","GHI"},"ABCD"));
System.out.println(w.countPaths(new String[]{"AA","AA"},"AAAA"));
System.out.println(w.countPaths(new String[]{"ABABA","BABAB","ABABA","BABAB","ABABA"},"ABABABBA"));
System.out.println(w.countPaths(new String[]{"AAAAA","AAAAA","AAAAA","AAAAA","AAAAA"},"AAAAAAAAAAA"));
System.out.println(w.countPaths(new String[]{"AB","CD"},"AA"));
System.out.println(w.countPaths(new String[]{"AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA"},"AAAAAAAAAAAAAAAAAAAA"));
System.out.println(w.countPaths(new String[]{"AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA"},"AAAAAAAAAAAAAAAAAAAAA"));
}
}
public class WordPath {
public long countPaths(String[] grid, String find){
int rowCount = grid.length;
int cellCount=grid[0].length();
char[][] charGrid = new char[rowCount][cellCount];
long[][] m = new long[rowCount][cellCount],m1 = new long[rowCount][cellCount];
for(int y=0;y<rowCount;y++)
for(int x=0;x<cellCount;x++)
if (find.charAt(0)==(charGrid[y][x]=grid[y].charAt(x))) m[y][x]=1;
for(int i=1;i<find.length();i++){
char ch = find.charAt(i);
for(int y=0;y<rowCount;y++){
for(int x=0;x<cellCount;x++){
if(ch == charGrid[y][x]){
if(y>0){
if(x>0)m1[y][x]+=m[y-1][x-1];
m1[y][x]+=m[y-1][x];
if(x<cellCount-1) m1[y][x]+=m[y-1][x+1];
}
if(x>0)m1[y][x]+=m[y][x-1];
if(x<cellCount-1) m1[y][x]+=m[y][x+1];
if(y<rowCount-1){
if(x>0) m1[y][x]+=m[y+1][x-1];
m1[y][x]+=m[y+1][x];
if(x<cellCount-1) m1[y][x]+=m[y+1][x+1];
}
}
}
}
m=m1;m1= new long[rowCount][cellCount];
}
long result = 0;
for(int i=0;i<rowCount;i++)for(int j=0;j<cellCount;j++) if(m[i][j]<0||(result += m[i][j])<0)return -1;
return result;
}
public static void main(String[] args){
WordPath w = new WordPath();
System.out.println(w.countPaths(new String[]{"ABC","FED","GHI"},"ABCDEFGHI"));
System.out.println(w.countPaths(new String[]{"ABC","FED","GAI"},"ABCDEA"));
System.out.println(w.countPaths(new String[]{"ABC","DEF","GHI"},"ABCD"));
System.out.println(w.countPaths(new String[]{"AA","AA"},"AAAA"));
System.out.println(w.countPaths(new String[]{"ABABA","BABAB","ABABA","BABAB","ABABA"},"ABABABBA"));
System.out.println(w.countPaths(new String[]{"AAAAA","AAAAA","AAAAA","AAAAA","AAAAA"},"AAAAAAAAAAA"));
System.out.println(w.countPaths(new String[]{"AB","CD"},"AA"));
System.out.println(w.countPaths(new String[]{"AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA"},"AAAAAAAAAAAAAAAAAAAA"));
System.out.println(w.countPaths(new String[]{"AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA","AAAAAAAA"},"AAAAAAAAAAAAAAAAAAAAA"));
}
}
re: 百度就知道吹 emu 2005-12-15 15:28
發現一個合二為一的網站,好玩!
http://www.baigoogledu.com/
http://www.baigoogledu.com/
re: google中國編程挑戰賽資格賽真題 -- WordPath(750分) emu 2005-12-15 15:26
:) 用動態規劃,時間只是隨參數大小線性增長的,再慢都很快
re: google中國編程挑戰賽資格賽真題 -- WordPath(750分) emu 2005-12-15 10:59
就是今年的東亞code jam大賽啊。不過在資格賽就刷下來了,我覺得有點冤的,入圍的不見得都是什么高手。模擬題和資格賽題收集在http://www.aygfsteel.com/emu/category/2769.html
這里火藥味越來越重了哦 emu 2005-12-15 10:53
都有人罵起粗話來啦!其實沒有必要啦,Brain從小到大參加過多少編程競賽,你說哪次競賽沒有一點運氣的成份在里面呢?14年前我的朋友彭煳在省賽的時候居然在保存結果的時候格式化錯了磁盤(當年還是用軟盤的),與冠軍失之交臂,樓主的遭遇不比他更差吧。13年前地區數學競賽的時候我最有實力的對手在賽前居然突發麻疹,眼睜睜看我把獎拿了,樓主沒他倒霉吧。是金子始終會發光的,彭煳后來去了微軟亞洲研究院。
google這次確實準備不足,沒有在電信、網通、教育網里面全部架好競賽平臺,對很多選手是很不公平的。不過要是我很重視這個競賽的話,賽前一定會找找朋友同學家里的線路測試一下哪里比較穩定,提前過去安好開發調試環境,反正有24小時的自由參賽時間,下班后挑個合適的時間特地過去一考一趟就好了。
樓主對 google大賽 還有興趣的話可以到我的 http://www.aygfsteel.com/emu/category/2769.html 看看最近兩次大賽的題目和解答。后面的幾輪要是能弄到題目也會帖出來,也希望看到樓主的解答。
樓主要是真的想挑戰難度的話不妨試試: http://www.aygfsteel.com/emu/articles/10196.html 我還沒見到誰解出來了。
google這次確實準備不足,沒有在電信、網通、教育網里面全部架好競賽平臺,對很多選手是很不公平的。不過要是我很重視這個競賽的話,賽前一定會找找朋友同學家里的線路測試一下哪里比較穩定,提前過去安好開發調試環境,反正有24小時的自由參賽時間,下班后挑個合適的時間特地過去一考一趟就好了。
樓主對 google大賽 還有興趣的話可以到我的 http://www.aygfsteel.com/emu/category/2769.html 看看最近兩次大賽的題目和解答。后面的幾輪要是能弄到題目也會帖出來,也希望看到樓主的解答。
樓主要是真的想挑戰難度的話不妨試試: http://www.aygfsteel.com/emu/articles/10196.html 我還沒見到誰解出來了。
re: google中國編程挑戰賽資格賽真題 -- WordPath(750分) emu 2005-12-14 21:55
>>google在出題上并沒有在時間和空間上給予難度。
其實還是會有的。上次東亞我記得是8秒,這次有人說限定是2秒。這個要求對于正確的算法是非常寬松的,但是對于錯誤的算法就是一個過不去的坎了。象這道題,我第一次的解法就是在時間復雜度上有問題。
其實還是會有的。上次東亞我記得是8秒,這次有人說限定是2秒。這個要求對于正確的算法是非常寬松的,但是對于錯誤的算法就是一個過不去的坎了。象這道題,我第一次的解法就是在時間復雜度上有問題。
re: google中國編程挑戰賽資格賽真題 -- WordPath(750分) emu 2005-12-14 12:47
上回貼的時候沒有做好符號替換,貼出來的代碼很多都顯示不出來,剛剛才發現。難怪你看了覺得不象動態規劃。
遞推的過程只需要保留上一步驟的結果和當前計算中的步驟的中間結果就可以了,沒有必要用三維數組保存全部推導狀態。
遞推的過程只需要保留上一步驟的結果和當前計算中的步驟的中間結果就可以了,沒有必要用三維數組保存全部推導狀態。
re: google中國編程挑戰賽資格賽真題 -- WordPath(750分) emu 2005-12-13 18:02
我難道不是用動態規劃、三重循環嗎?
emu 更正的解法 emu 2005-12-13 16:48
看看,和alphabet是不是一樣:
public class WordPath {
public int countPaths(String[] grid, String find){
int rowCount = grid.length;
int cellCount=grid[0].length();
char[][] charGrid = new char[rowCount][cellCount];
int[][] m = new int[rowCount][cellCount],m1 = new int[rowCount][cellCount];
for(int y=0;y<rowCount;y++)
for(int x=0;x<cellCount;x++)
if (find.charAt(0)==(charGrid[y][x]=grid[y].charAt(x))) m[y][x]=1;
for(int i=1;i<find.length();i++){
char ch = find.charAt(i);
for(int y=0;y<rowCount;y++){
for(int x=0;x<cellCount;x++){
if(ch == charGrid[y][x]){
if(y>0){
if(x>0)m1[y][x]+=m[y-1][x-1];
m1[y][x]+=m[y-1][x];
if(x<cellCount-1) m1[y][x]+=m[y-1][x+1];
}
if(x>0)m1[y][x]+=m[y][x-1];
if(x<cellCount-1) m1[y][x]+=m[y][x+1];
if(y<rowCount-1){
if(x>0) m1[y][x]+=m[y+1][x-1];
m1[y][x]+=m[y+1][x];
if(x<cellCount-1) m1[y][x]+=m[y+1][x+1];
}
}
}
}
m=m1;m1= new int[rowCount][cellCount];
}
int result = 0;
for(int i=0;i<rowCount;i++)for(int j=0;j<cellCount;j++) if((result += m[i][j])>1000000000)return -1;
return result;
}
public static void main(String[] args){
WordPath w = new WordPath();
System.out.println(w.countPaths(new String[]{"ABC","FED","GHI"},"ABCDEFGHI"));
System.out.println(w.countPaths(new String[]{"ABC","FED","GAI"},"ABCDEA"));
System.out.println(w.countPaths(new String[]{"ABC","DEF","GHI"},"ABCD"));
System.out.println(w.countPaths(new String[]{"AA","AA"},"AAAA"));
System.out.println(w.countPaths(new String[]{"ABABA","BABAB","ABABA","BABAB","ABABA"},"ABABABBA"));
System.out.println(w.countPaths(new String[]{"AAAAA","AAAAA","AAAAA","AAAAA","AAAAA"},"AAAAAAAAAAA"));
System.out.println(w.countPaths(new String[]{"AB","CD"},"AA"));
}
}
public class WordPath {
public int countPaths(String[] grid, String find){
int rowCount = grid.length;
int cellCount=grid[0].length();
char[][] charGrid = new char[rowCount][cellCount];
int[][] m = new int[rowCount][cellCount],m1 = new int[rowCount][cellCount];
for(int y=0;y<rowCount;y++)
for(int x=0;x<cellCount;x++)
if (find.charAt(0)==(charGrid[y][x]=grid[y].charAt(x))) m[y][x]=1;
for(int i=1;i<find.length();i++){
char ch = find.charAt(i);
for(int y=0;y<rowCount;y++){
for(int x=0;x<cellCount;x++){
if(ch == charGrid[y][x]){
if(y>0){
if(x>0)m1[y][x]+=m[y-1][x-1];
m1[y][x]+=m[y-1][x];
if(x<cellCount-1) m1[y][x]+=m[y-1][x+1];
}
if(x>0)m1[y][x]+=m[y][x-1];
if(x<cellCount-1) m1[y][x]+=m[y][x+1];
if(y<rowCount-1){
if(x>0) m1[y][x]+=m[y+1][x-1];
m1[y][x]+=m[y+1][x];
if(x<cellCount-1) m1[y][x]+=m[y+1][x+1];
}
}
}
}
m=m1;m1= new int[rowCount][cellCount];
}
int result = 0;
for(int i=0;i<rowCount;i++)for(int j=0;j<cellCount;j++) if((result += m[i][j])>1000000000)return -1;
return result;
}
public static void main(String[] args){
WordPath w = new WordPath();
System.out.println(w.countPaths(new String[]{"ABC","FED","GHI"},"ABCDEFGHI"));
System.out.println(w.countPaths(new String[]{"ABC","FED","GAI"},"ABCDEA"));
System.out.println(w.countPaths(new String[]{"ABC","DEF","GHI"},"ABCD"));
System.out.println(w.countPaths(new String[]{"AA","AA"},"AAAA"));
System.out.println(w.countPaths(new String[]{"ABABA","BABAB","ABABA","BABAB","ABABA"},"ABABABBA"));
System.out.println(w.countPaths(new String[]{"AAAAA","AAAAA","AAAAA","AAAAA","AAAAA"},"AAAAAAAAAAA"));
System.out.println(w.countPaths(new String[]{"AB","CD"},"AA"));
}
}
emu解 BusStops emu 2005-12-13 14:23
public class BusStops
{
public int countStops(String[] cityMap, int walkingDistance){
int x=-1,y=-1,result=0;
for(int i=0;i<cityMap.length;i++){
if(cityMap[i].indexOf("X")>-1){
y=i;x=cityMap[i].indexOf("X");
break;
}
}
for(int i=0;i<cityMap.length;i++){
String s = cityMap[i];
for(int j=0;j<s.length();j++){
if(s.charAt(j)=='B'){
int a= Math.abs(y-i)+Math.abs(x-j);
if(a<=walkingDistance) result++;
}
}
}
return result;
}
public static void main(String[] args)
{
BusStops b = new BusStops();
System.out.println(b.countStops( new String[]{"...B.",".....","..X.B",".....","B...."},3));
System.out.println(b.countStops( new String[]{"B.B..",".....","B....",".....","....X"},8));
System.out.println(b.countStops( new String[]{"BBBBB","BB.BB","B.X.B","BB.BB","BBBBB"},1));
System.out.println(b.countStops( new String[]{"B..B..",".B...B","..B...","..B.X.","B.B.B.",".B.B.B"},3));
}
}
{
public int countStops(String[] cityMap, int walkingDistance){
int x=-1,y=-1,result=0;
for(int i=0;i<cityMap.length;i++){
if(cityMap[i].indexOf("X")>-1){
y=i;x=cityMap[i].indexOf("X");
break;
}
}
for(int i=0;i<cityMap.length;i++){
String s = cityMap[i];
for(int j=0;j<s.length();j++){
if(s.charAt(j)=='B'){
int a= Math.abs(y-i)+Math.abs(x-j);
if(a<=walkingDistance) result++;
}
}
}
return result;
}
public static void main(String[] args)
{
BusStops b = new BusStops();
System.out.println(b.countStops( new String[]{"...B.",".....","..X.B",".....","B...."},3));
System.out.println(b.countStops( new String[]{"B.B..",".....","B....",".....","....X"},8));
System.out.println(b.countStops( new String[]{"BBBBB","BB.BB","B.X.B","BB.BB","BBBBB"},1));
System.out.println(b.countStops( new String[]{"B..B..",".B...B","..B...","..B.X.","B.B.B.",".B.B.B"},3));
}
}
emu 解 FillBaskets emu 2005-12-13 14:20
public class FillBaskets {
public int countWays(int baskets, int capacity, int balls){
if(balls==0) return 1;
if(baskets == 1)
if (balls<=capacity) return 1; else return 0;
int result = 0;
for(int i=0;i<=capacity&&i<=balls;i++){
result += countWays(baskets-1,capacity,balls-i);
}
return result;
}
}
public int countWays(int baskets, int capacity, int balls){
if(balls==0) return 1;
if(baskets == 1)
if (balls<=capacity) return 1; else return 0;
int result = 0;
for(int i=0;i<=capacity&&i<=balls;i++){
result += countWays(baskets-1,capacity,balls-i);
}
return result;
}
}
emu的錯誤解法 emu 2005-12-13 13:27
public class WordPath
{
int resultCount;
public int countPaths(String[] grid, String find){
int rowCount = grid.length;
int cellCount=grid[0].length();
resultCount = 0;
char[][] charGrid = new char[rowCount][cellCount];
for(int y=0;y<rowCount;y++)
for(int x=0;x<cellCount;x++)
charGrid[y][x] = grid[y].charAt(x);
for(int y=0;y<rowCount;y++){
for(int x=0;x<cellCount;x++){
if(charGrid[y][x]==find.charAt(0)){
doCount(charGrid,find.substring(1),x,y);
}
if(resultCount<0) return -1;
}
}
return resultCount;
}
private void doCount(char[][] c,String find,int x,int y){
if(resultCount<0) return;
if(find.length()==0) {
resultCount++;
if(resultCount>10000000) resultCount=-1;
return;
}
if(y>0){
if(c[y-1][x]==find.charAt(0))
doCount(c,find.substring(1),x,y-1);
if(resultCount<0) return ;
if(x>0 && c[y-1][x-1]==find.charAt(0))
doCount(c,find.substring(1),x-1,y-1);
if(resultCount<0) return ;
if(x<c[0].length-1 && c[y-1][x+1]==find.charAt(0))
doCount(c,find.substring(1),x+1,y-1);
}
if(resultCount<0) return ;
if(y<(c.length-1)){
if(c[y+1][x]==find.charAt(0))
doCount(c,find.substring(1),x,y+1);
if(resultCount<0) return ;
if(x>0 && c[y+1][x-1]==find.charAt(0))
doCount(c,find.substring(1),x-1,y+1);
if(resultCount<0) return ;
if(x<c[0].length-1 && c[y+1][x+1]==find.charAt(0))
doCount(c,find.substring(1),x+1,y+1);
}
if(resultCount<0) return ;
if(x>0 && c[y][x-1]==find.charAt(0))
doCount(c,find.substring(1),x-1,y);
if(resultCount<0) return ;
if(x<c[0].length-1 && c[y][x+1]==find.charAt(0)){
doCount(c,find.substring(1),x+1,y);
}
return;
}
public static void main(String[] args){
WordPath w = new WordPath();
System.out.println(w.countPaths(new String[]{"ABC","FED","GHI"},"ABCDEFGHI"));
System.out.println(w.countPaths(new String[]{"ABC","FED","GAI"},"ABCDEA"));
System.out.println(w.countPaths(new String[]{"ABC","DEF","GHI"},"ABCD"));
System.out.println(w.countPaths(new String[]{"AA","AA"},"AAAA"));
System.out.println(w.countPaths(new String[]{"ABABA","BABAB","ABABA","BABAB","ABABA"},"ABABABBA"));
System.out.println(w.countPaths(new String[]{"AAAAA","AAAAA","AAAAA","AAAAA","AAAAA"},"AAAAAAAAAAA"));
System.out.println(w.countPaths(new String[]{"AB","CD"},"AA"));
}
}
時間復雜度太高。當時沒有好好想想。和alphabet同出一轍啊!該死!
{
int resultCount;
public int countPaths(String[] grid, String find){
int rowCount = grid.length;
int cellCount=grid[0].length();
resultCount = 0;
char[][] charGrid = new char[rowCount][cellCount];
for(int y=0;y<rowCount;y++)
for(int x=0;x<cellCount;x++)
charGrid[y][x] = grid[y].charAt(x);
for(int y=0;y<rowCount;y++){
for(int x=0;x<cellCount;x++){
if(charGrid[y][x]==find.charAt(0)){
doCount(charGrid,find.substring(1),x,y);
}
if(resultCount<0) return -1;
}
}
return resultCount;
}
private void doCount(char[][] c,String find,int x,int y){
if(resultCount<0) return;
if(find.length()==0) {
resultCount++;
if(resultCount>10000000) resultCount=-1;
return;
}
if(y>0){
if(c[y-1][x]==find.charAt(0))
doCount(c,find.substring(1),x,y-1);
if(resultCount<0) return ;
if(x>0 && c[y-1][x-1]==find.charAt(0))
doCount(c,find.substring(1),x-1,y-1);
if(resultCount<0) return ;
if(x<c[0].length-1 && c[y-1][x+1]==find.charAt(0))
doCount(c,find.substring(1),x+1,y-1);
}
if(resultCount<0) return ;
if(y<(c.length-1)){
if(c[y+1][x]==find.charAt(0))
doCount(c,find.substring(1),x,y+1);
if(resultCount<0) return ;
if(x>0 && c[y+1][x-1]==find.charAt(0))
doCount(c,find.substring(1),x-1,y+1);
if(resultCount<0) return ;
if(x<c[0].length-1 && c[y+1][x+1]==find.charAt(0))
doCount(c,find.substring(1),x+1,y+1);
}
if(resultCount<0) return ;
if(x>0 && c[y][x-1]==find.charAt(0))
doCount(c,find.substring(1),x-1,y);
if(resultCount<0) return ;
if(x<c[0].length-1 && c[y][x+1]==find.charAt(0)){
doCount(c,find.substring(1),x+1,y);
}
return;
}
public static void main(String[] args){
WordPath w = new WordPath();
System.out.println(w.countPaths(new String[]{"ABC","FED","GHI"},"ABCDEFGHI"));
System.out.println(w.countPaths(new String[]{"ABC","FED","GAI"},"ABCDEA"));
System.out.println(w.countPaths(new String[]{"ABC","DEF","GHI"},"ABCD"));
System.out.println(w.countPaths(new String[]{"AA","AA"},"AAAA"));
System.out.println(w.countPaths(new String[]{"ABABA","BABAB","ABABA","BABAB","ABABA"},"ABABABBA"));
System.out.println(w.countPaths(new String[]{"AAAAA","AAAAA","AAAAA","AAAAA","AAAAA"},"AAAAAAAAAAA"));
System.out.println(w.countPaths(new String[]{"AB","CD"},"AA"));
}
}
時間復雜度太高。當時沒有好好想想。和alphabet同出一轍啊!該死!
re: 兩件小事讓我抓狂 之二:Google編程大賽瘋狂掉線 emu 2005-12-13 10:02
游戲規則如此,google在全世界都是這樣競賽的,在中國很難開這個例外。
周末有一個大哥跟我說,中國人的問題不是不會變通,是太會變通了。
什么都變通了,還有什么規則可言?
我覺得抱怨歸抱怨,游戲規則是一早就定下來了的,還是要遵守。
周末有一個大哥跟我說,中國人的問題不是不會變通,是太會變通了。
什么都變通了,還有什么規則可言?
我覺得抱怨歸抱怨,游戲規則是一早就定下來了的,還是要遵守。
re: ImageLayers(入圍賽750分真題) emu 2005-12-12 15:23
750分題的時間復雜度降不下來,看來通不過資格賽了,可惜……
emu的解法 emu 2005-12-12 12:09
小飛俠,應該吧打印結果部分從函數中抽出來。
我的解法是:
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));
}
}
我的解法是:
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));
}
}