122062024-12-09 12:33:07CsongiSzámjegycserecpp17Wrong answer 0/100170ms708 KiB
#include <bits/stdc++.h>
using namespace std;

bool ketnulla(const string& str)
{
    int szam = 0;
    for (char c : str)
    {
        if (c=='0')
        {
            szam++;
        }
        if (szam == 2)
        {
            return true;
        }
    }
    return false;
}


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n; cin >> n;
    for (int i = 0; i < n; i++)
    {
        string be; cin >> be;
        //string be = to_string(be);
        if (be.size() == 1)
        {
            if (be == "0")
            {
                cout << "0" << endl;
            }
            else
            {
                cout << "-1" << endl;
            }
        }
        else if ((be[be.size()-1]=='0' && be[be.size()-2]=='0') || (be[be.size()-1]=='5' && be[be.size()-2]=='2') || (be[be.size()-1]=='5' && be[be.size()-2]=='7') || (be[be.size()-1]=='0' && be[be.size()-2]=='5'))
        {
            cout << "0" << endl;
        }
        else if (be[be.size()-1]=='0')
        {
            string str = be; str.pop_back();
            if (str.find("0") != string::npos || str.find("5") != string::npos)
            {
                cout << "1" << endl;
            }
            else
            {
                cout << "-1" << endl;
            }
        }
        else if (be[be.size()-2]=='0')
        {
            string str = be; char x = str.back(); str.pop_back(); str.pop_back(); str.push_back(x);
            if (str.find("0") != string::npos)
            {
                cout << "1" << endl;
            }
            else if (str.find("5") != string::npos)
            {
                cout << "2" << endl;
            }
            else
            {
                cout << "-1" << endl;
            }
        }
        else if (be[be.size()-1]=='5')
        {
            string str = be; str.pop_back();
            if (str.find("7") != string::npos || str.find("2") != string::npos || be[be.size()-2]=='0')
            {
                cout << "1" << endl;
            }
            else if (ketnulla(str))
            {
                cout << "2" << endl;
            }
            else
            {
                cout << "-1" << endl;
            }
        }
        else if ((be[be.size()-1]=='2' && be[be.size()-2]=='5') || (be[be.size()-1]=='7' && be[be.size()-2]=='5'))
        {
            cout << "1" << endl;
        }
        else if ((be.find("7") != string::npos && be.find("5") != string::npos) || (be.find("2") != string::npos && be.find("5") != string::npos) || (be.find("5") != string::npos && be.find("0") != string::npos) || ketnulla(be))
        {
            cout << "2" << endl;
        }
        else
        {
            cout << "-1" << endl;
        }
    }
    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
subtask20/21
2Wrong answer46ms320 KiB
subtask30/23
3Wrong answer164ms708 KiB
4Wrong answer163ms568 KiB
5Wrong answer167ms428 KiB
6Wrong answer168ms568 KiB
7Wrong answer170ms508 KiB
8Wrong answer170ms560 KiB
9Wrong answer163ms568 KiB
10Wrong answer162ms444 KiB
11Wrong answer162ms568 KiB
12Wrong answer162ms568 KiB
13Wrong answer167ms568 KiB
14Wrong answer167ms456 KiB
15Wrong answer162ms568 KiB
16Wrong answer160ms564 KiB
17Wrong answer166ms452 KiB
18Wrong answer165ms460 KiB
19Wrong answer163ms452 KiB
20Wrong answer168ms568 KiB
21Wrong answer168ms444 KiB
22Wrong answer163ms476 KiB
23Wrong answer136ms568 KiB
subtask40/41
24Accepted1ms500 KiB
25Accepted1ms508 KiB
26Accepted1ms320 KiB
27Accepted1ms320 KiB
28Accepted1ms320 KiB
29Accepted1ms508 KiB
30Accepted1ms320 KiB
31Accepted1ms352 KiB
32Accepted1ms320 KiB
33Wrong answer1ms332 KiB
34Accepted1ms320 KiB
35Accepted1ms320 KiB
36Accepted2ms320 KiB
37Accepted14ms508 KiB
38Accepted1ms320 KiB
39Accepted1ms320 KiB
40Accepted1ms500 KiB
41Accepted1ms508 KiB
42Accepted2ms320 KiB
43Accepted2ms320 KiB
44Accepted2ms504 KiB
45Accepted2ms320 KiB
46Wrong answer1ms500 KiB
47Wrong answer2ms320 KiB
subtask50/15
48Wrong answer4ms320 KiB
49Wrong answer3ms684 KiB
50Wrong answer158ms576 KiB
51Wrong answer3ms320 KiB
52Wrong answer35ms392 KiB
53Accepted3ms320 KiB
54Accepted4ms320 KiB
55Accepted18ms452 KiB
56Accepted160ms568 KiB
57Accepted3ms588 KiB
58Accepted4ms588 KiB
59Accepted3ms588 KiB
60Accepted4ms320 KiB
61Accepted4ms320 KiB
62Accepted4ms440 KiB
63Accepted4ms352 KiB
64Accepted160ms696 KiB
65Accepted158ms696 KiB
66Accepted159ms568 KiB