原文
https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1870
感謝ZERO JUDGE的翻譯
https://zerojudge.tw/ShowProblem?problemid=d235
C++
#include <iostream>
#include <string>
using namespace std;
int main()
{
string is1;//數字會很大用字串來處理
while(cin>>is1)//輸入
{
if(is1=="0")//輸入0代表結束
{
break;
}
int odd=0,even=0;//odd計算奇數位數的加總
//even計算偶數位數的加總
for(int i=0;i<is1.length();i++)//計算奇數偶位數加總
{
if(i%2==1)//計算奇數位數加總
{
odd=odd+(is1[i]-'0');//字串某一個字來計算會用ASCII碼
//因為數字的ASCII碼相連
//所以減掉'0'的ASCII碼就是字串的數字了
}
else
{
even=even+(is1[i]-'0');
}
}
if((odd-even)%11==0)//奇偶位數整除11就是11的倍數
{
cout<<is1<<" is a multiple of 11."<<endl;
}
else
{
cout<<is1<<" is not a multiple of 11."<<endl;
}
}
return 0;
}
文章標籤
全站熱搜

原本在搜尋引擎找出一堆 Blog 文章,不知哪幾篇值得花時間一看, 後來用 PTT搜尋引擎,輾轉看到您這的好文而有緣來到這, 謝謝您用心分享有價值的內容, 也回饋給您這實用的主題排名網站資訊,可查看與您 Blog 內容相關的排名好文,應該對寫 Blog 也有所幫助,期待您持續產出好文章 ^^ https://searchptt.cc/