[ZJd235][UVA10929] You can say 11
題目:
http://zerojudge.tw/ShowProblem?problemid=d235
------------------------------------------------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
while(cin >> s)
{
if(s == "0")break;
int a = 0, b = 0;
for(int i=0;i<s.length();i++)
{
if(i % 2 == 0)
a = a + (s[i] - '0');
else
b = b + (s[i] - '0');
}
if((a - b) % 11 == 0)
cout << s <<" is a multiple of 11.\n";
else
cout << s <<" is not a multiple of 11.\n";
}
return 0;
}
http://zerojudge.tw/ShowProblem?problemid=d235
------------------------------------------------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
while(cin >> s)
{
if(s == "0")break;
int a = 0, b = 0;
for(int i=0;i<s.length();i++)
{
if(i % 2 == 0)
a = a + (s[i] - '0');
else
b = b + (s[i] - '0');
}
if((a - b) % 11 == 0)
cout << s <<" is a multiple of 11.\n";
else
cout << s <<" is not a multiple of 11.\n";
}
return 0;
}
留言
張貼留言