12207 | 2024-12-09 12:37:42 | Csongi | Számjegycsere | cpp17 | Wrong answer 0/100 | 170ms | 764 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 (be[be.size()-1]=='5')
{
cout << "1" << endl;
}
else 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 1ms | 320 KiB | ||||
subtask2 | 0/21 | ||||||
2 | Wrong answer | 46ms | 472 KiB | ||||
subtask3 | 0/23 | ||||||
3 | Wrong answer | 163ms | 568 KiB | ||||
4 | Wrong answer | 163ms | 568 KiB | ||||
5 | Wrong answer | 168ms | 568 KiB | ||||
6 | Wrong answer | 170ms | 568 KiB | ||||
7 | Wrong answer | 162ms | 564 KiB | ||||
8 | Wrong answer | 168ms | 568 KiB | ||||
9 | Wrong answer | 162ms | 660 KiB | ||||
10 | Wrong answer | 166ms | 448 KiB | ||||
11 | Wrong answer | 163ms | 764 KiB | ||||
12 | Wrong answer | 170ms | 444 KiB | ||||
13 | Wrong answer | 163ms | 436 KiB | ||||
14 | Wrong answer | 168ms | 448 KiB | ||||
15 | Wrong answer | 167ms | 452 KiB | ||||
16 | Wrong answer | 163ms | 452 KiB | ||||
17 | Wrong answer | 167ms | 468 KiB | ||||
18 | Wrong answer | 162ms | 568 KiB | ||||
19 | Wrong answer | 168ms | 564 KiB | ||||
20 | Wrong answer | 163ms | 568 KiB | ||||
21 | Wrong answer | 170ms | 568 KiB | ||||
22 | Wrong answer | 163ms | 692 KiB | ||||
23 | Wrong answer | 136ms | 568 KiB | ||||
subtask4 | 0/41 | ||||||
24 | Accepted | 1ms | 320 KiB | ||||
25 | Accepted | 1ms | 376 KiB | ||||
26 | Accepted | 1ms | 320 KiB | ||||
27 | Accepted | 1ms | 516 KiB | ||||
28 | Accepted | 1ms | 320 KiB | ||||
29 | Accepted | 1ms | 320 KiB | ||||
30 | Accepted | 1ms | 320 KiB | ||||
31 | Accepted | 1ms | 320 KiB | ||||
32 | Accepted | 1ms | 320 KiB | ||||
33 | Wrong answer | 1ms | 320 KiB | ||||
34 | Accepted | 1ms | 320 KiB | ||||
35 | Accepted | 1ms | 552 KiB | ||||
36 | Accepted | 2ms | 320 KiB | ||||
37 | Accepted | 14ms | 432 KiB | ||||
38 | Accepted | 1ms | 320 KiB | ||||
39 | Accepted | 1ms | 340 KiB | ||||
40 | Accepted | 1ms | 536 KiB | ||||
41 | Accepted | 1ms | 332 KiB | ||||
42 | Accepted | 2ms | 508 KiB | ||||
43 | Accepted | 2ms | 320 KiB | ||||
44 | Accepted | 3ms | 320 KiB | ||||
45 | Accepted | 2ms | 320 KiB | ||||
46 | Wrong answer | 1ms | 320 KiB | ||||
47 | Wrong answer | 2ms | 320 KiB | ||||
subtask5 | 0/15 | ||||||
48 | Wrong answer | 4ms | 320 KiB | ||||
49 | Wrong answer | 3ms | 568 KiB | ||||
50 | Wrong answer | 153ms | 440 KiB | ||||
51 | Wrong answer | 2ms | 468 KiB | ||||
52 | Wrong answer | 37ms | 320 KiB | ||||
53 | Accepted | 3ms | 320 KiB | ||||
54 | Accepted | 4ms | 444 KiB | ||||
55 | Accepted | 20ms | 508 KiB | ||||
56 | Accepted | 151ms | 704 KiB | ||||
57 | Accepted | 3ms | 588 KiB | ||||
58 | Accepted | 3ms | 588 KiB | ||||
59 | Accepted | 3ms | 588 KiB | ||||
60 | Accepted | 4ms | 464 KiB | ||||
61 | Accepted | 4ms | 436 KiB | ||||
62 | Accepted | 4ms | 452 KiB | ||||
63 | Accepted | 4ms | 320 KiB | ||||
64 | Accepted | 170ms | 716 KiB | ||||
65 | Accepted | 167ms | 568 KiB | ||||
66 | Accepted | 157ms | 604 KiB |