close
題目概要:
將輸入的字串進行解碼。
解題方向:
1. 建立一個鍵盤的字串方便查詢。
2. 將輸入的字依序比較step1 所建立的表進行比較,當找到相同字元時,輸出前第2個位子的字元。 Ex 表:qwer 當輸入r時,對照表並輸出前第2個位子的字元w。
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Java | |
import java.util.Scanner; | |
class uva10222{ | |
public static void main(String args[]){ | |
Scanner sc=new Scanner(System.in); | |
String st="`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./"; //建立對照的表 | |
while(sc.hasNextLine()){ | |
String s=sc.nextLine().toLowerCase(); | |
//進行字元比較,並輸出隊的字元 | |
for(int i=0;i<s.length();i++){ | |
if(s.charAt(i)==' '){ | |
System.out.print(" "); | |
}else{ | |
for(int j=0;j<st.length();j++){ | |
if(s.charAt(i)==st.charAt(j)){ | |
if(j-2>0) System.out.print(st.charAt(j-2)); | |
else System.out.print(s.charAt(i)); | |
break; | |
} | |
} | |
} | |
} | |
System.out.println(""); | |
} | |
} | |
} |
文章標籤
全站熱搜