SHANKS - Editorial

PROBLEM:

Shanks Devil Fruit

DIFFICULTY:

Easy

PREREQUISITES:

None

PROBLEM:

Given a number N you have to determine if it is divisible by 3 or not.

EXPLANATION:

Normally we would just store the input in int and use % operator to determine if it is divisible or not. But considering the constraints its not possible to store such big number in int datatype. So we create a string variable and store input in it, then iterate through entire string looking at each digit and determine if whole number is divisible by 3 or not.

SOLUTION:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ll t;
    cin >> t;
    while(t--)
    {
        string s;
        cin >> s;
        int mod = 0;
        for(int i=0; i<s.size(); i++)
        {
            int num = s[i]-'0';
            mod = (mod + num) % 3;
        }
        if(mod == 0)
            cout << "YOS" << '\n';
        else
            cout << "YADA" << '\n';
    }
  return 0;
}