https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1870 困難度 ★ 這題測資過大所以要以字串存取然後再把偶數位的和和奇數位的和的差去判斷是否為11的倍數
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while(scn.hasNext()){
String str=scn.nextLine();
if(str.equals("0"))break;
char[]arr=str.toCharArray();
int a=0,b=0;
for(int i=0;i<arr.length;i++){
if(i%2==0)a+=arr[i]-'0';
else b+=arr[i]-'0';
}
if((a-b)%11==0)
System.out.println(str+" is a multiple of 11.");
else
System.out.println(str+" is not a multiple of 11.");
}
}
/*
題目:Q10929: You can say 11
作者:1010
時間:西元 2016 年 7 月 */
}