andy6804tw
7/17/2016 - 12:23 PM

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=29264 這題非常險惡測了第28次才AC,必須注意題目敘述3個限制 1.字元必須都不是包含0的數字(不用考慮省略) 2.字元必須是奇數(我是用字串下去讀

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=29264 這題非常險惡測了第28次才AC,必須注意題目敘述3個限制 1.字元必須都不是包含0的數字(不用考慮省略) 2.字元必須是奇數(我是用字串下去讀然後檢查長度是否為奇數個) 3.其數值不大於INT正值上限(這個其實包含在項2項了,因為測資中大於INT上限的值似乎是偶數個字母) 4.另外我發現測資第2個一直不過的原因是字串內不能包含0~9以外的數字

import java.util.*;  
  
public class Main {  
  
    public static void main(String[] args) {  
        Scanner scn = new Scanner(System.in);  
        String str=scn.next();  
        char s[]=str.toCharArray();  
        int i=0,j=s.length-1;  
        boolean b=true;  
        while(i<j){  
            if((s[i]!=s[j])||(s[i]<='0'||s[i]>='9')){  
                b=true;  
                break;  
            }  
            else  
                b=false;  
            i++;j--;  
        }  
        if(b||s.length%2==0)  
            System.out.println("FALSE");  
        else   
            System.out.println("TRUE");  
    } 
    	/* 
    題目:[C_AR156-易] 迴文
    作者:1010
    時間:西元 2016 年 7 月 */
}