andy6804tw
7/20/2016 - 1:13 AM

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=3671 這題讀取字元當A時=>14 J=>11 Q=>12 K=>13 因為是讀取字元只有一個字可是可能會出現10這個數字排裡面沒有1這個數字(被A取

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=3671

這題讀取字元當A時=>14 J=>11 Q=>12 K=>13 因為是讀取字元只有一個字可是可能會出現10這個數字排裡面沒有1這個數字(被A取代)所以當讀到1時就代表是10

import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		while (scn.hasNext()) {
			char c;
			int tot = 0;
			for (int i = 0; i < 5; i++) {
				c = scn.next().charAt(0);
				if (c == 'A')
					tot += 14;
				else if (c == 'J')
					tot += 11;
				else if (c == 'Q')
					tot += 12;
				else if (c == 'K')
					tot += 13;
				else if (c == '1')//1這個數字(被A取代)所以當讀到1時就代表是10
					tot += 10;
				else
					tot += c - '0';
			}
			System.out.println(tot);
		}
	}
	
	/* 
    題目:[C_AR66-易] 撲克牌13點
    作者:1010
    時間:西元 2016 年 7 月 */
}