#29822: 請問為什麼 WA


narutoooo1771@gmail.com (トンカツ)


#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;

}

#29824: Re:請問為什麼 WA


cges30901 (cges30901)


#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