2020年3月7日 星期六

[zerojudge]a065. 提款卡密碼

a065. 提款卡密碼

迴圈次數
很顯然你只要跑n-1次迴圈兩兩比對就可以了。
字元可以做運算,酷吧!

程式碼如下:

  1. /* Pa065.java
  2. * a065. 提款卡密碼
  3. *
  4. * 科皓不要
  5. * 2020/3/7
  6. */
  7.  
  8. import java.util.Scanner;
  9.  
  10. public class Pa065{
  11.  
  12. public static void main(String[] args){
  13. Scanner scanner = new Scanner(System.in);
  14.  
  15. while(scanner.hasNext()){
  16. char[] chs = scanner.next().toCharArray();
  17. for(int i = 0; i < chs.length - 1; i++){
  18. System.out.print(Math.abs(chs[i] - chs[i+1]));
  19. }
  20.  
  21. System.out.println();
  22. }
  23. }
  24. }

沒有留言:

張貼留言