#include <iostream>
#include <string>
using namespace std;
int main()
{
string n;
int digit, index;
long long int digits = 0;
while (getline(cin, n))
{
index = 0;
if (n[0] == '-')
{
n[0] = 0;
index = 1;
}
for (index; index < n.length(); index++)
{
digit = n[index] - '0';
digits += digit;
}
if (digits % 3 == 0)
{
cout << "yes\n";
}
else
{
cout << "no\n";
}
n.clear();
}
return 0;
}
#include
#include
using namespace std;
int main()
{
string n;
int digit, index;
long long int digits = 0;
while (getline(cin, n))
{
index = 0;
if (n[0] == '-')
{
n[0] = 0;
index = 1;
}
for (index; index < n.length(); index++)
{
digit = n[index] - '0';
digits += digit;
}
if (digits % 3 == 0)
{
cout << "yes\n";
}
else
{
cout << "no\n";
}
n.clear();
}
return 0;
}
要在while迴圈內把digits重設為0