andy6804tw
7/17/2016 - 3:03 PM

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3710 困難度 ★ 這題輸入只有1,2,3三種可能所以主要是判斷1和因為這兩個數字的英

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3710 困難度 ★ 這題輸入只有1,2,3三種可能所以主要是判斷1和因為這兩個數字的英文字母都只有三個 所以利用indexOf(' ')下去做搜尋,>=0代表字串中有該字母

import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		while (n-- != 0) {
			String str = scn.next();
			char arr[] = str.toCharArray();
			if (arr.length == 5)
				System.out.println("3");
			else if (str.indexOf('n') >= 0
					|| (str.indexOf('e') >= 0 && (str.indexOf('o') >= 0 || str.indexOf('n') >= 0))
					|| (str.indexOf('o') >= 0 && (str.indexOf('n') >= 0 || str.indexOf('e') >= 0)))
				System.out.println("1");
			else
				System.out.println("2");
		}
	}
		/* 
    題目:Q12289 : One-Two-Three
    作者:1010
    時間:西元 2016 年 7 月 */
}