Runtime error on test 2 (1266A)

Правка en1, от genijalac, 2020-01-06 17:38:43

Hi,

I am attempting to solve 1266A (Competitive Programmer), but I get a runtime error on test 2. This is my code:

include <bits/stdc++.h>

using namespace std;

bool dijeljivost_3 (string x) { int X = stoi(x); int zbir = 0; while (X!=0) { int cifra = X%10; zbir += cifra; X /= 10; } return (zbir%3==0); }

bool dijeljivost_4_5(string X) { if (X.find_first_of('0') != string::npos) { X.erase(X.find_first_of('0'), 1); if (X.find('0') != string::npos || X.find('2') != string::npos || X.find('4') != string::npos || X.find('6') != string::npos || X.find('8') != string::npos) { return true; } } return false; }

int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);

int n;
cin >> n;

while (n--) {
    string y;
    cin >> y;
    if ((dijeljivost_3(y) && dijeljivost_4_5(y)) || stoi(y)==0)
        cout << "red\n";
    else
        cout << "cyan\n";
}

return 0;

}

The idea of the code is to check whether the number is divisible by 3, 4 and 5. This would mean it is divisible by 60(since 3, 4 and 5 are relatively prime). Can someone tell me what is wrong with my code?

Теги #beginner, mysterious runtime error

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский genijalac 2020-01-06 17:42:15 86
en2 Английский genijalac 2020-01-06 17:40:30 1242
en1 Английский genijalac 2020-01-06 17:38:43 1556 Initial revision (published)