# UVA 10929 You can say 11 ## 題目連結 [UVA 10929](https://vjudge.net/problem/UVA-10929) ### 題目內容 Your job is, given a positive number N, determine if it is a multiple of eleven ### 輸入限制 The input is a file such that each line contains a positive number. A line containing the number ‘0’ is the end of the input. The given numbers can contain up to 1000 digits. ### 輸出限制 The output of the program shall indicate, for each input number, if it is a multiple of eleven or not. ### 解題思路 建立大小為2的sum陣列來存放奇數與偶數,判斷依據是看%2的餘數,計算差距是否為11的倍數。 ### 程式碼 ```cpp= #include<bits/stdc++.h> using namespace std; int main(){ string n; while(cin>>n && n!="0"){ int sum[2]={0}; for(int i=0;i<n.length();i++){ sum[i%2]+=n[i]-'0'; } int ans=abs(sum[0]-sum[1]); if(ans%11==0){ cout<<n<<" is a multiple of 11."<<endl; } else{ cout<<n<<" is not a multiple of 11."<<endl; } } } ``` ## 測資 ### Sample input 112233 30800 2937 323455693 5038297 112234 0 ### Sample output 112233 is a multiple of 11. 30800 is a multiple of 11. 2937 is a multiple of 11. 323455693 is a multiple of 11. 5038297 is a multiple of 11. 112234 is not a multiple of 11. ## 中文題目連結 [zerojudge d235](https://zerojudge.tw/ShowProblem?problemid=d235)