作者MephistoH (默非斯托)
看板java
標題Re: [問題]今年台銀IT人員招考試題
時間Mon Nov 22 11:56:29 2010
為啥要寫這裡麻煩??
不就是把 ascII碼都加上位移數就好了嗎 = =?
我改一下你的程式 .
※ 引述《bleed1979 (十三)》之銘言:
public class Encoding {
public static void main(String[] args) {
System.out.println(new Compress().go(65488973,"MEET ME XXX"));
}
}
class Compress {
public String go(int k, String inPutString) {
k=k%26; //一定要看到%你才高興?
char[] inputChar=inPutString.toCharArray();
StringBuffer outputString =new StringBuffer();
for(int i=0;inputChar.length>i;i++){
if(!(inputChar[i]==' ')){
inputChar[i]= (char)((int)inputChar[i] + k);
if(inputChar[i]>'Z'){
inputChar[i]=(char)(inputChar[i]-26); //超過Z要從頭
}
outputString.append(inputChar[i]);
}else{
//有空格要填進去
outputString.append(inputChar[i]);
}
}
return outputString.toString();
}
}
這樣超過Z就從頭啦
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.120.109.150
推 LPH66:呃, 'Z'+3 會變成 ']' 喔....(雖然不是什麼大問題就是) 11/22 13:59
→ bleed1979:一切的一切都是為了省%運算。 11/22 20:08
→ derekQQ:ㄎ,到底要省運算還是省buffer~ 11/22 21:43
※ 編輯: MephistoH 來自: 59.120.109.150 (11/23 08:03)
→ bleed1979:k=20101123,本程式應該RE吧,請解題。 11/23 13:09
→ bleed1979:不過應該要看compile怎麼實作轉型。 11/23 13:11
※ 編輯: MephistoH 來自: 59.120.109.150 (11/23 14:05)