a065. 提款卡密碼

很顯然你只要跑n-1次迴圈兩兩比對就可以了。
字元可以做運算,酷吧!
程式碼如下:
/* Pa065.java
* a065. 提款卡密碼
*
* 科皓不要
* 2020/3/7
*/
import java.util.Scanner;
public class Pa065{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()){
char[] chs = scanner.next().toCharArray();
for(int i = 0; i < chs.length - 1; i++){
System.out.print(Math.abs(chs[i] - chs[i+1]));
}
System.out.println();
}
}
}
沒有留言:
張貼留言